Advertisement
nghiahsgs

Untitled

Apr 16th, 2017
1,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.89 KB | None | 0 0
  1. #include-once
  2. #include <String.au3>
  3.  
  4. ; Config-section
  5. Global $BvSsh_path = @ScriptDir & "\Bitvise" ; path to Bitvise
  6. Global $BvSsh_listenInterface = "0.0.0.0" ; or 127.0.0.1
  7. Global $BvSsh_listenPort = 1080 ; or 8080
  8. Global $BvSsh_timeOut = 10 ; or 30 (seconds)
  9. Global $BvSsh_hideAll = False ; True/False - Hide All Bitvise GUI
  10. Global $BvSsh_pID
  11.  
  12. If _BvSsh_Login('65.111.168.104', 'john', 'password') Then
  13.     MsgBox(0, 'OK', 'Connection Successfully!')
  14. Else
  15.     MsgBox(0, 'Error', 'Connection Error!')
  16. EndIf
  17.  
  18. Func _BvSsh_Login($host, $user, $pass)
  19.     ProcessClose($BvSsh_pID)
  20.     Sleep(1000)
  21.  
  22.     Local $BvSsh_profile = _HexToString('0000000E54756E6E656C69657220342E3532000000000000001600000000000000000000000000000000000000000000000B627364617574682C7' & _
  23.             '0616D01010001020000000200000000000005787465726D010000FDE900000050000000190000012C07010000000000000000000D3132372E302E302E313A302E3000000000000000' & _
  24.             '0000000000000000093132372E302E302E3100000D3D00000000000000000000000000000000010000000101010101010101000001010101000001010101000000012C01000000000' & _
  25.             '0000000000001' & _ipToHex($BvSsh_listenInterface) & '0000000' & StringLen($BvSsh_listenPort) & _StringToHex($BvSsh_listenPort) & '000000000000000' & _
  26.             '000007F00000100000002323100000000010101000000000000000000000000000000010100000001010000000000000000000000000000000000000200')
  27.  
  28.     RegWrite("HKEY_CURRENT_USER\Software\Bitvise" & $BvSsh_listenPort & "\BvSshClient", 'DefaultProfile', 'REG_BINARY', $BvSsh_profile)
  29.  
  30.     _BvSsh_runCmd($host, $user, $pass, $BvSsh_listenPort)
  31.  
  32.     Return _BvSsh_waitConnected($BvSsh_listenPort, $BvSsh_timeOut * 1000)
  33. EndFunc   ;==>_BvSsh_Login
  34.  
  35. Func _BvSsh_runCmd($iHost, $iUser, $iPass, $iPort)
  36.     Local $Cmd = $BvSsh_path & "\BvSsh.exe -host=" & $iHost & " -port=22 -user=" & $iUser & " -password=" & $iPass & _
  37.             " -loginOnStartup -exitOnLogout -baseRegistry=HKEY_CURRENT_USER\Software\Bitvise" & $iPort
  38.  
  39.     If $BvSsh_hideAll Then
  40.         $Cmd &= " -menu=small -hide=popups,trayLog,trayPopups,trayIcon"
  41.     EndIf
  42.  
  43.     $BvSsh_pID = Run($Cmd)
  44.     ProcessWait($BvSsh_pID)
  45.  
  46.     Sleep(1500)
  47. EndFunc   ;==>_BvSsh_runCmd
  48.  
  49. Func _BvSsh_waitConnected($port, $time_out = 10000, $delay = 80)
  50.     Local $timer_int = TimerInit()
  51.     While TimerDiff($timer_int) < $time_out
  52.         If Not ProcessExists($BvSsh_pID) Then ExitLoop
  53.         If _BvSsh_checkConnection($port) Then Return TimerDiff($timer_int)
  54.         Sleep($delay)
  55.     WEnd
  56.  
  57.     Return 0
  58. EndFunc   ;==>_BvSsh_waitConnected
  59.  
  60. Func _BvSsh_checkConnection($port)
  61.     TCPStartup()
  62.     Local $connection = TCPConnect("127.0.0.1", $port)
  63.     If $connection <> -1 Then
  64.         TCPCloseSocket($connection)
  65.         TCPShutdown()
  66.         Return 1
  67.     Else
  68.         TCPShutdown()
  69.         Return 0
  70.     EndIf
  71. EndFunc   ;==>_BvSsh_checkConnection
  72.  
  73. Func _ipToHex($ip)
  74.     Local $ipSplit = StringSplit($ip, ".")
  75.     If UBound($ipSplit) < 4 Then Return 0
  76.     Return Hex($ipSplit[1], 2) & Hex($ipSplit[2], 2) & Hex($ipSplit[3], 2) & Hex($ipSplit[4], 2)
  77. EndFunc   ;==>_ipToHex
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement