0

I have a mining application that shows the data I need but the application doesn't have an api to grab it. How can I extract the string to parse the data with powershell or equivalent?

The data drops a line like below every second,

ID(grabbed from board) hash:(label) hashrate(variable) errors:(label) #(variable) temp(variable) volts(variable) solutions:(label) #(variable) shares:(label) #(variable)

Example:

ABC1000234 hash: 9.8Gh/s errors: 0.000% 26.3C 0.74V solutions: 539/539 shares: 33

I need the hashrate, temp and volts or even better a way to send every string out to a port I can listen on to a url like "strings". If I can get the string to post to a port such as 4068. Then I could use powershell and netcat to listen to the port on http://127.0.0.1:4068.

Here is what I was going to do for powershell:

$serveraddress = '127.0.0.1' 

$serverport = '4068'

$threadinfo = echo 'strings' | nc $serveraddress $serverport

$mineridstring = $stringsinfo.Split(';')[1] $minderid =
$mineridstring.Split('=')[0]

$hashstring = $stringsinfo.Split(';')[2] $hash =
$hashstring.Split('=')[1]

$tempstring = $stringsinfo.Split(';')[4] $tempc =
$tempstring.Split('=')[0]

$voltstring = $stringsinfo.Split(';')[5] $volts =
$voltsstring.Split('=')[0]

Invoke-RestMethod -Uri https://www.rigmanager.xyz/rig.php -Method Post `
-Body @{minerid = $minerid; hashrate = $hashrate; tempc = $temp; $volts = $volts} -UseBasicParsing
JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
Invento
  • 1
  • 1
  • I appreciate your willingness to keep improving your question, but it's still hard to understand from the abstract sample what the exact requirements are. Try to post _concrete, representative_ samples, and supplement with a description of the format. Generally, strive for an [MCVE (Minimal, Complete, and Verifiable Example)](http://stackoverflow.com/help/mcve) or as close as you can get to one. – mklement0 Nov 11 '18 at 23:21
  • Please put an example in the question. Is it??? `ID 237 hash:123 errors:#456...`? – lit Nov 12 '18 at 13:23
  • Added some more background and example. Sorry for the lack of info. Am I missing anything? – Invento Nov 12 '18 at 14:23
  • Is this understanding correct: You have a program ("mining application"). This program is producing output. The output is to its console. You want to find a way to capture this output (potentially using PowerShell), and parse it to pull back the relevant values (e.g. temperature, voltage). You can't code the program itself; so you need a way to pull data from its console output. – JohnLBevan Nov 13 '18 at 16:45
  • If my understanding's correct, you may want to look at this: https://stackoverflow.com/a/8762068/361842 – JohnLBevan Nov 13 '18 at 16:47
  • JohnLBevan that is exsctly what I am trying to do. Cool, I'll check the link! – Invento Nov 13 '18 at 16:53

2 Answers2

0

Push them to a message queue, and then you can subscribe any number of users/applications to that stream.

Check out Apache Kafka or any of the cloud-based equivalents on AWS, IBM Cloud, GCP, etc.

Parsing your string is something regex can handle, although unless you need the data indexed for querying/searching, you can pushing that off to the end user/application and just serve them the whole message.

John R
  • 1,505
  • 10
  • 18
0

An easy way to do this is with named captures in a regex.

PS C:\src\t> type  exttext.ps1
$s = 'ABC1000234 hash: 9.8Gh/s errors: 0.000% 26.3C 0.74V solutions: 539/539 shares: 33'

$doesit = $s -match '^(?<id>.*) hash: (?<hashrate>.*) errors: (?<errors>[0-9.]+%) (?<temp>.*) (?<volts>.*) solutions: .* shares: \d+$'

$Matches.id
$Matches.hashrate
$Matches.errors
$Matches.temp
$Matches.volts

PS C:\src\t> .\exttext.ps1
ABC1000234
9.8Gh/s
0.000%
26.3C
0.74V
lit
  • 14,456
  • 10
  • 65
  • 119