Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.Text
- Imports System.Threading
- Imports System.Net.Sockets
- Imports Renci.SshNet
- Imports System.IO
- Imports System.Text.RegularExpressions
- Public Class Main
- Public Shared Property clientssh As SshClient
- Public Shared Property shellStream As ShellStream
- Public Shared Property clientssh2 As SshClient
- Public Shared Property shellStream2 As ShellStream
- Public Shared Property clientssh3 As SshClient
- Public Shared Property shellStream3 As ShellStream
- Public Shared Property clientssh4 As SshClient
- Public Shared Property shellStream4 As ShellStream
- Public Shared Property clientssh5 As SshClient
- Public Shared Property shellStream5 As ShellStream
- Public UserDataFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
- Dim PathProg As String = "C:\"
- Const READ_BUFFER_SIZE As Integer = 20000
- Public readBuffer(READ_BUFFER_SIZE) As Byte
- Const PORT_NUM As Integer = 4028
- Public NBConnection As Integer
- Public DataMiner As New DataTable
- Public UserName As String
- Public Password As String
- Public SysDate As DateTime
- Private clients As New Hashtable
- Private IPTABLE As New Hashtable
- Private listener As TcpListener
- Private listenerThread As Threading.Thread
- Public client As TcpClient
- Public Function Connect(ByVal sender As System.Object, server As String, port As String)
- UserName = "root"
- Password = "admin"
- Try
- ' The TcpClient is a subclass of Socket, providing higher level
- ' functionality like streaming.
- client = New TcpClient(server, port)
- ' Start an asynchronous read invoking DoRead to avoid lagging the user
- ' interface.
- client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE, AddressOf DoRead, Nothing)
- ' Make sure the window is showing before popping up connection dialog.
- AttemptLogin()
- Catch Ex As Exception
- MsgBox("connection error no active miner",
- MsgBoxStyle.Critical, "Connection error")
- End Try
- End Function
- Public Sub AttemptLogin()
- Dim dat As String = "lcd"
- SendData(dat)
- End Sub
- Public Sub SendData(ByVal data As String)
- Try
- Dim writer As New IO.StreamWriter(client.GetStream, Encoding.Default, data.Length)
- SyncLock client.GetStream
- writer.Write(data)
- writer.Flush()
- End SyncLock
- EndSend:
- Catch ex As Exception
- Dim o As String = ex.ToString
- Dim a As String = ex.Message
- Exit Sub
- End Try
- End Sub
- Public Sub DoRead(ByVal ar As IAsyncResult)
- Dim BytesRead As Integer
- Dim strMessage As String
- Try
- ' Finish asynchronous read into readBuffer and return number of bytes read.
- BytesRead = client.GetStream.EndRead(ar)
- ' Convert the byte array the message was saved into, minus two for the
- ' Chr(13) and Chr(10)
- strMessage = Encoding.Default.GetString(readBuffer, 0, BytesRead)
- If strMessage = "" Then
- GoTo ENDFUNCTION
- Else
- If InStr(strMessage, "Msg") <> 0 Then
- Dim msg1 As String
- Dim desc As String
- msg1 = Split(strMessage, "Msg=")(1)
- msg1 = Split(msg1, ",")(0)
- desc = Split(strMessage, "Description=")(1)
- desc = Split(desc, "|")(1)
- MsgBox(msg1 & vbCrLf & desc, MsgBoxStyle.Information, "Miners response")
- End If
- End If
- Catch e As Exception
- End Try
- ENDFUNCTION:
- End Sub
- Private Sub ManuallyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ManuallyToolStripMenuItem.Click
- Dim Minerwizard As New MinerAdd
- Minerwizard.MdiParent = Me
- Minerwizard.StartPosition = FormStartPosition.CenterScreen
- Minerwizard.Show()
- End Sub
- Private Sub ToolsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ToolsToolStripMenuItem.Click
- End Sub
- Private Sub DesktopToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DesktopToolStripMenuItem.Click
- Dim Desktop As New Desktop
- Desktop.MdiParent = Me
- Desktop.WindowState = FormWindowState.Normal
- Desktop.StartPosition = FormStartPosition.CenterScreen
- Desktop.Show()
- Desktop.WindowState = FormWindowState.Maximized
- End Sub
- Private Sub APIConfigToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles APIConfigToolStripMenuItem.Click
- Dim API As New APIPriv
- API.MdiParent = Me
- API.StartPosition = FormStartPosition.CenterScreen
- API.Show()
- API.WindowState = FormWindowState.Normal
- End Sub
- Public Shared Function ReturnSShStats(IpMiner As String, Username As String, Password As String, command As String)
- Try
- Dim outputFrom As String
- clientssh = New SshClient(IpMiner, Username, Password)
- clientssh.Connect()
- Dim reply As String = String.Empty
- shellStream = clientssh.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
- Dim reader = New StreamReader(shellStream)
- Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
- reply = shellStream.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
- shellStream.WriteLine(command)
- Dim result As String = shellStream.ReadLine(New TimeSpan(0, 0, 1))
- outputFrom = reader.ReadToEnd()
- Loop
- clientssh.Disconnect()
- clientssh.Dispose()
- Return (outputFrom)
- Catch ex As Exception
- Return ("")
- End Try
- End Function
- Public Shared Function ReturnSShStats2(IpMiner As String, Username As String, Password As String, command As String)
- Try
- Dim outputFrom As String
- clientssh2 = New SshClient(IpMiner, Username, Password)
- clientssh2.Connect()
- Dim reply As String = String.Empty
- shellStream2 = clientssh2.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
- Dim reader = New StreamReader(shellStream2)
- Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
- reply = shellStream2.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
- shellStream2.WriteLine(command)
- Dim result As String = shellStream2.ReadLine(New TimeSpan(0, 0, 1))
- outputFrom = reader.ReadToEnd()
- Loop
- clientssh2.Disconnect()
- clientssh2.Dispose()
- Return (outputFrom)
- Catch ex As Exception
- Return ("")
- End Try
- End Function
- Public Shared Function ReturnSShStats3(IpMiner As String, Username As String, Password As String, command As String)
- Try
- Dim outputFrom As String
- clientssh3 = New SshClient(IpMiner, Username, Password)
- clientssh3.Connect()
- Dim reply As String = String.Empty
- shellStream3 = clientssh3.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
- Dim reader = New StreamReader(shellStream3)
- Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
- reply = shellStream3.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
- shellStream3.WriteLine(command)
- Dim result As String = shellStream3.ReadLine(New TimeSpan(0, 0, 1))
- outputFrom = reader.ReadToEnd()
- Loop
- clientssh3.Disconnect()
- clientssh3.Dispose()
- Return (outputFrom)
- Catch ex As Exception
- Return ("")
- End Try
- End Function
- Public Shared Function ReturnSShStats4(IpMiner As String, Username As String, Password As String, command As String)
- Try
- Dim outputFrom As String
- clientssh4 = New SshClient(IpMiner, Username, Password)
- clientssh4.Connect()
- Dim reply As String = String.Empty
- shellStream4 = clientssh4.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
- Dim reader = New StreamReader(shellStream4)
- Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
- reply = shellStream4.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
- shellStream4.WriteLine(command)
- Dim result As String = shellStream4.ReadLine(New TimeSpan(0, 0, 1))
- outputFrom = reader.ReadToEnd()
- Loop
- clientssh4.Disconnect()
- clientssh4.Dispose()
- Return (outputFrom)
- Catch ex As Exception
- Return ("")
- End Try
- End Function
- Public Shared Function ReturnSShStats5(IpMiner As String, Username As String, Password As String, command As String)
- Try
- Dim outputFrom As String
- clientssh5 = New SshClient(IpMiner, Username, Password)
- clientssh5.Connect()
- Dim reply As String = String.Empty
- shellStream5 = clientssh5.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
- Dim reader = New StreamReader(shellStream5)
- Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
- reply = shellStream5.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
- shellStream5.WriteLine(command)
- Dim result As String = shellStream5.ReadLine(New TimeSpan(0, 0, 1))
- outputFrom = reader.ReadToEnd()
- Loop
- clientssh5.Disconnect()
- clientssh5.Dispose()
- Return (outputFrom)
- Catch ex As Exception
- Return ("")
- End Try
- End Function
- Private Sub UpgradeMinerToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UpgradeMinerToolStripMenuItem.Click
- Dim Um As New updateminer
- Um.MdiParent = Me
- Um.StartPosition = FormStartPosition.CenterScreen
- Um.Show()
- Um.WindowState = FormWindowState.Normal
- End Sub
- Private Sub ConfigMinerBatchToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ConfigMinerBatchToolStripMenuItem.Click
- Dim Um As New MinerBatchConfig
- Um.MdiParent = Me
- Um.StartPosition = FormStartPosition.CenterScreen
- Um.Show()
- Um.WindowState = FormWindowState.Normal
- Um.TextBox1.Focus()
- End Sub
- Private Sub RestartRequest(minerip As String, minertype As String)
- End Sub
- Private Sub Main_Load(sender As Object, e As EventArgs) Handles Me.Load
- DataMiner.Columns.Add("IP", GetType(String))
- DataMiner.Columns.Add("Temp", GetType(String))
- DataMiner.Columns.Add("GH", GetType(String))
- DataMiner.Columns.Add("GHA", GetType(String))
- DataMiner.Columns.Add("Accept", GetType(String))
- DataMiner.Columns.Add("Reject", GetType(String))
- DataMiner.Columns.Add("Discard", GetType(String))
- DataMiner.Columns.Add("HWE", GetType(String))
- DataMiner.Columns.Add("PS", GetType(String))
- DataMiner.Columns.Add("MS", GetType(String))
- DataMiner.Columns.Add("Type", GetType(String))
- DataMiner.Columns.Add("LastValueSSH", GetType(String))
- DataMiner.Columns.Add("LastValueSSHSummary", GetType(String))
- DataMiner.Columns.Add("Howmanystate", GetType(String))
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement