Advertisement
Guest User

main alex

a guest
Apr 26th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 11.95 KB | None | 0 0
  1.  
  2. Imports System
  3. Imports System.Text
  4. Imports System.Threading
  5. Imports System.Net.Sockets
  6. Imports Renci.SshNet
  7. Imports System.IO
  8. Imports System.Text.RegularExpressions
  9.  
  10. Public Class Main
  11.     Public Shared Property clientssh As SshClient
  12.     Public Shared Property shellStream As ShellStream
  13.     Public Shared Property clientssh2 As SshClient
  14.     Public Shared Property shellStream2 As ShellStream
  15.     Public Shared Property clientssh3 As SshClient
  16.     Public Shared Property shellStream3 As ShellStream
  17.     Public Shared Property clientssh4 As SshClient
  18.     Public Shared Property shellStream4 As ShellStream
  19.     Public Shared Property clientssh5 As SshClient
  20.     Public Shared Property shellStream5 As ShellStream
  21.     Public UserDataFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
  22.     Dim PathProg As String = "C:\"
  23.  
  24.  
  25.     Const READ_BUFFER_SIZE As Integer = 20000
  26.     Public readBuffer(READ_BUFFER_SIZE) As Byte
  27.     Const PORT_NUM As Integer = 4028
  28.     Public NBConnection As Integer
  29.     Public DataMiner As New DataTable
  30.     Public UserName As String
  31.     Public Password As String
  32.     Public SysDate As DateTime
  33.     Private clients As New Hashtable
  34.     Private IPTABLE As New Hashtable
  35.     Private listener As TcpListener
  36.     Private listenerThread As Threading.Thread
  37.     Public client As TcpClient
  38.  
  39.  
  40.     Public Function Connect(ByVal sender As System.Object, server As String, port As String)
  41.         UserName = "root"
  42.         Password = "admin"
  43.  
  44.  
  45.         Try
  46.             ' The TcpClient is a subclass of Socket, providing higher level
  47.             ' functionality like streaming.
  48.  
  49.             client = New TcpClient(server, port)
  50.  
  51.             ' Start an asynchronous read invoking DoRead to avoid lagging the user
  52.             ' interface.
  53.             client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE, AddressOf DoRead, Nothing)
  54.  
  55.             ' Make sure the window is showing before popping up connection dialog.
  56.             AttemptLogin()
  57.  
  58.         Catch Ex As Exception
  59.  
  60.             MsgBox("connection error no active miner",
  61.                    MsgBoxStyle.Critical, "Connection error")
  62.         End Try
  63.     End Function
  64.  
  65.     Public Sub AttemptLogin()
  66.         Dim dat As String = "lcd"
  67.         SendData(dat)
  68.     End Sub
  69.  
  70.     Public Sub SendData(ByVal data As String)
  71.         Try
  72.  
  73.  
  74.             Dim writer As New IO.StreamWriter(client.GetStream, Encoding.Default, data.Length)
  75.             SyncLock client.GetStream
  76.                 writer.Write(data)
  77.                 writer.Flush()
  78.             End SyncLock
  79. EndSend:
  80.         Catch ex As Exception
  81.             Dim o As String = ex.ToString
  82.             Dim a As String = ex.Message
  83.  
  84.             Exit Sub
  85.  
  86.  
  87.         End Try
  88.     End Sub
  89.  
  90.     Public Sub DoRead(ByVal ar As IAsyncResult)
  91.         Dim BytesRead As Integer
  92.         Dim strMessage As String
  93.         Try
  94.             ' Finish asynchronous read into readBuffer and return number of bytes read.
  95.             BytesRead = client.GetStream.EndRead(ar)
  96.  
  97.  
  98.             ' Convert the byte array the message was saved into, minus two for the
  99.             ' Chr(13) and Chr(10)
  100.             strMessage = Encoding.Default.GetString(readBuffer, 0, BytesRead)
  101.  
  102.  
  103.             If strMessage = "" Then
  104.                 GoTo ENDFUNCTION
  105.             Else
  106.                 If InStr(strMessage, "Msg") <> 0 Then
  107.                     Dim msg1 As String
  108.                     Dim desc As String
  109.                     msg1 = Split(strMessage, "Msg=")(1)
  110.                     msg1 = Split(msg1, ",")(0)
  111.                     desc = Split(strMessage, "Description=")(1)
  112.                     desc = Split(desc, "|")(1)
  113.                     MsgBox(msg1 & vbCrLf & desc, MsgBoxStyle.Information, "Miners response")
  114.                 End If
  115.             End If
  116.  
  117.         Catch e As Exception
  118.  
  119.         End Try
  120. ENDFUNCTION:
  121.     End Sub
  122.  
  123.     Private Sub ManuallyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ManuallyToolStripMenuItem.Click
  124.         Dim Minerwizard As New MinerAdd
  125.         Minerwizard.MdiParent = Me
  126.         Minerwizard.StartPosition = FormStartPosition.CenterScreen
  127.         Minerwizard.Show()
  128.     End Sub
  129.  
  130.     Private Sub ToolsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ToolsToolStripMenuItem.Click
  131.  
  132.     End Sub
  133.  
  134.     Private Sub DesktopToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DesktopToolStripMenuItem.Click
  135.         Dim Desktop As New Desktop
  136.         Desktop.MdiParent = Me
  137.         Desktop.WindowState = FormWindowState.Normal
  138.         Desktop.StartPosition = FormStartPosition.CenterScreen
  139.         Desktop.Show()
  140.         Desktop.WindowState = FormWindowState.Maximized
  141.     End Sub
  142.  
  143.     Private Sub APIConfigToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles APIConfigToolStripMenuItem.Click
  144.         Dim API As New APIPriv
  145.         API.MdiParent = Me
  146.         API.StartPosition = FormStartPosition.CenterScreen
  147.         API.Show()
  148.         API.WindowState = FormWindowState.Normal
  149.     End Sub
  150.  
  151.     Public Shared Function ReturnSShStats(IpMiner As String, Username As String, Password As String, command As String)
  152.  
  153.         Try
  154.             Dim outputFrom As String
  155.  
  156.  
  157.             clientssh = New SshClient(IpMiner, Username, Password)
  158.             clientssh.Connect()
  159.             Dim reply As String = String.Empty
  160.             shellStream = clientssh.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
  161.             Dim reader = New StreamReader(shellStream)
  162.  
  163.             Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
  164.                 reply = shellStream.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
  165.  
  166.                 shellStream.WriteLine(command)
  167.  
  168.  
  169.                 Dim result As String = shellStream.ReadLine(New TimeSpan(0, 0, 1))
  170.                 outputFrom = reader.ReadToEnd()
  171.  
  172.             Loop
  173.             clientssh.Disconnect()
  174.             clientssh.Dispose()
  175.             Return (outputFrom)
  176.         Catch ex As Exception
  177.             Return ("")
  178.         End Try
  179.  
  180.     End Function
  181.  
  182.     Public Shared Function ReturnSShStats2(IpMiner As String, Username As String, Password As String, command As String)
  183.  
  184.         Try
  185.             Dim outputFrom As String
  186.  
  187.  
  188.             clientssh2 = New SshClient(IpMiner, Username, Password)
  189.             clientssh2.Connect()
  190.             Dim reply As String = String.Empty
  191.             shellStream2 = clientssh2.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
  192.             Dim reader = New StreamReader(shellStream2)
  193.  
  194.             Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
  195.                 reply = shellStream2.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
  196.  
  197.                 shellStream2.WriteLine(command)
  198.  
  199.  
  200.                 Dim result As String = shellStream2.ReadLine(New TimeSpan(0, 0, 1))
  201.                 outputFrom = reader.ReadToEnd()
  202.  
  203.             Loop
  204.             clientssh2.Disconnect()
  205.             clientssh2.Dispose()
  206.             Return (outputFrom)
  207.         Catch ex As Exception
  208.             Return ("")
  209.         End Try
  210.  
  211.     End Function
  212.  
  213.     Public Shared Function ReturnSShStats3(IpMiner As String, Username As String, Password As String, command As String)
  214.  
  215.         Try
  216.             Dim outputFrom As String
  217.  
  218.  
  219.             clientssh3 = New SshClient(IpMiner, Username, Password)
  220.             clientssh3.Connect()
  221.             Dim reply As String = String.Empty
  222.             shellStream3 = clientssh3.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
  223.             Dim reader = New StreamReader(shellStream3)
  224.  
  225.             Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
  226.                 reply = shellStream3.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
  227.  
  228.                 shellStream3.WriteLine(command)
  229.  
  230.  
  231.                 Dim result As String = shellStream3.ReadLine(New TimeSpan(0, 0, 1))
  232.                 outputFrom = reader.ReadToEnd()
  233.  
  234.             Loop
  235.             clientssh3.Disconnect()
  236.             clientssh3.Dispose()
  237.             Return (outputFrom)
  238.         Catch ex As Exception
  239.             Return ("")
  240.         End Try
  241.  
  242.     End Function
  243.  
  244.     Public Shared Function ReturnSShStats4(IpMiner As String, Username As String, Password As String, command As String)
  245.  
  246.         Try
  247.             Dim outputFrom As String
  248.  
  249.  
  250.             clientssh4 = New SshClient(IpMiner, Username, Password)
  251.             clientssh4.Connect()
  252.             Dim reply As String = String.Empty
  253.             shellStream4 = clientssh4.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
  254.             Dim reader = New StreamReader(shellStream4)
  255.  
  256.             Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
  257.                 reply = shellStream4.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
  258.  
  259.                 shellStream4.WriteLine(command)
  260.  
  261.  
  262.                 Dim result As String = shellStream4.ReadLine(New TimeSpan(0, 0, 1))
  263.                 outputFrom = reader.ReadToEnd()
  264.  
  265.             Loop
  266.             clientssh4.Disconnect()
  267.             clientssh4.Dispose()
  268.             Return (outputFrom)
  269.         Catch ex As Exception
  270.             Return ("")
  271.         End Try
  272.  
  273.     End Function
  274.  
  275.     Public Shared Function ReturnSShStats5(IpMiner As String, Username As String, Password As String, command As String)
  276.  
  277.         Try
  278.             Dim outputFrom As String
  279.  
  280.  
  281.             clientssh5 = New SshClient(IpMiner, Username, Password)
  282.             clientssh5.Connect()
  283.             Dim reply As String = String.Empty
  284.             shellStream5 = clientssh5.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
  285.             Dim reader = New StreamReader(shellStream5)
  286.  
  287.             Do Until InStr(outputFrom, "STATUS=S") > 0 Or InStr(outputFrom, "Connection refused") > 0
  288.                 reply = shellStream5.Expect(New Regex(":.*>#"), New TimeSpan(0, 0, 1))
  289.  
  290.                 shellStream5.WriteLine(command)
  291.  
  292.  
  293.                 Dim result As String = shellStream5.ReadLine(New TimeSpan(0, 0, 1))
  294.                 outputFrom = reader.ReadToEnd()
  295.  
  296.             Loop
  297.             clientssh5.Disconnect()
  298.             clientssh5.Dispose()
  299.             Return (outputFrom)
  300.         Catch ex As Exception
  301.             Return ("")
  302.         End Try
  303.  
  304.     End Function
  305.  
  306.  
  307.  
  308.     Private Sub UpgradeMinerToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UpgradeMinerToolStripMenuItem.Click
  309.         Dim Um As New updateminer
  310.         Um.MdiParent = Me
  311.         Um.StartPosition = FormStartPosition.CenterScreen
  312.         Um.Show()
  313.         Um.WindowState = FormWindowState.Normal
  314.     End Sub
  315.  
  316.     Private Sub ConfigMinerBatchToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ConfigMinerBatchToolStripMenuItem.Click
  317.         Dim Um As New MinerBatchConfig
  318.         Um.MdiParent = Me
  319.         Um.StartPosition = FormStartPosition.CenterScreen
  320.         Um.Show()
  321.         Um.WindowState = FormWindowState.Normal
  322.         Um.TextBox1.Focus()
  323.     End Sub
  324.  
  325.     Private Sub RestartRequest(minerip As String, minertype As String)
  326.  
  327.     End Sub
  328.  
  329.     Private Sub Main_Load(sender As Object, e As EventArgs) Handles Me.Load
  330.         DataMiner.Columns.Add("IP", GetType(String))
  331.         DataMiner.Columns.Add("Temp", GetType(String))
  332.         DataMiner.Columns.Add("GH", GetType(String))
  333.         DataMiner.Columns.Add("GHA", GetType(String))
  334.         DataMiner.Columns.Add("Accept", GetType(String))
  335.         DataMiner.Columns.Add("Reject", GetType(String))
  336.         DataMiner.Columns.Add("Discard", GetType(String))
  337.         DataMiner.Columns.Add("HWE", GetType(String))
  338.         DataMiner.Columns.Add("PS", GetType(String))
  339.         DataMiner.Columns.Add("MS", GetType(String))
  340.         DataMiner.Columns.Add("Type", GetType(String))
  341.         DataMiner.Columns.Add("LastValueSSH", GetType(String))
  342.         DataMiner.Columns.Add("LastValueSSHSummary", GetType(String))
  343.         DataMiner.Columns.Add("Howmanystate", GetType(String))
  344.  
  345.     End Sub
  346. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement