Title: Script for monitoring NiceHash results Post by: trinitrate on August 03, 2016, 02:54:52 AM Hey, I put this simple powershell script together to aid in checking on the status of miners. Its nothing fancy, but I wanted to play with PS and JSON a bit and this gave me an excuse to do it. Feel free to use / change it to your hearts desire. I understand a lot of guys on this board can make this on their own very easily (and probably better!). For those of you that can't, here's a head-start you can use to build a monitoring script of your own. Copy the text below into a text file with a 'ps1' file extension. You may have to either digitally sign the script or disable signature checking to run it. Disabling Signing - https://technet.microsoft.com/en-us/library/ee176961.aspx Self-signing (Optional) - https://community.spiceworks.com/how_to/122368-signing-a-powershell-script-with-a-self-signed-certificate Launch from the command prompt ./[scriptname].ps1 BTCAddress i.e. './CheckNiceHash.ps1 1JZRzjuf1rw9g3i9pFhLZKrMdQ7CzbBjLZ' Theres obviously nothing malicious in the code - feel free to read through it - its too simple to be dangerous! #Leverages NiceHash API to display the current mining stats for a given BTC address. Only shows active Algos or pending balance. # #This was written as a simple test to learn a bit about leveraging JSON, and learning a tiny bit of PowerShell. #Most of this code is rough and can be cleaned up quite a bit, but it is functional and can be used to build some #simple monitoring scripts for your own purposes. # #Provided for public use, no charge or credit needed. #BTC Donations: 1JZRzjuf1rw9g3i9pFhLZKrMdQ7CzbBjLZ function CheckMiner ([string]$addr) { $Request = "https://www.nicehash.com/api?method=stats.provider&addr=" + $addr $Result = Invoke-RestMethod -Uri $Request -Method Get $Rig = $Result.result.stats return $Rig } function PadTotal ([string]$Total) { [int]$TotalLen = $Total.Length [int]$MissingChar = 12 - $TotalLen if ($MissingChar -eq 11){ $Total = "0.00000000" $MissingChar = 0 } Do { #Write-host "made it!" $Total = $Total + "0" $MissingChar = $MissingChar-1 } While ($MissingChar -gt 0 ) return $Total } #build an array with all of the descriptive names of the Algos that NH will report back with $Algos = "Scrypt ","SHA256 ","ScryptNf ","X11 ","X13 ","Keccak ","X15 ","Nist5 ","NeoScrtpt ","Lyra2RE ","Whirlpoolx ","Qubit ","Quark ","Axiom ","Lyra2REv2 ","ScryptJaneNf16","Blake256r8","Blake256r14","Blake256r8vnl","Hodl ","DaggerHash ","Decred " #pass the BTC address at the command line $BTCAddress = $args #get the stats from the API $minerStats = CheckMiner ($BTCAddress) [float]$TotalHash = 0 [float]$TotalRej = 0 [float]$TotalBal = 0 cls $Now = Get-Date Write-host $Now "Stats for " $BTCAddress write-host "Algo Speed (GH/S) Rejected (GH/S) Balance " write-host "--------------------------------------------------------------" ForEach ($Algo in $minerStats) { $AlgoSpeed = $Algo.accepted_speed $AlgoBal = $Algo.balance $AlgoRej = $Algo.rejected_speed if($AlgoBal -ne "0.00000000") { $TotalHash = $TotalHash + $AlgoSpeed $TotalRej = $TotalRej + $AlgoRej $TotalBal = $TotalBal + $AlgoBal $AlgoName = $Algos[$Algo.algo] write-host $AlgoName " " $AlgoSpeed " " $AlgoRej " " $AlgoBal } } #add white space to the vars so they print to the screen a little better (Im sure there is a better way to do this!) $TotalHash2 = PadTotal($TotalHash) $TotalRej2 = PadTotal($TotalRej) $TotalBal2 = PadTotal($TotalBal) write-host "Total Speed: " $TotalHash2 " " $TotalRej2 " " $TotalBal2 |