Juno_okyo

Send request through sock/proxy

Jan 14th, 2015
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.53 KB | None | 0 0
  1. ; Example by piccaso
  2.  
  3. TCPStartup()
  4.  
  5. $hc = TCPConnect("192.168.0.100", 9050)                  ; Socks4a Proxy Server
  6.  
  7. $sReq = Chr(0x04) _                                     ; Protocol version  4
  8.       & Chr(0x01) _                                     ; Command Code      1 - establish a tcp/ip stream connection
  9.       & Chr(0x00) & Chr(0x50) _                         ; Port              80
  10.       & Chr(0x00) & Chr(0x00) & Chr(0x00) & Chr(0xFF) _ ; Ip Adress         Invalid - 0.0.0.255
  11.       & "" & Chr(0x00) _                                ; User Id           Empty
  12.       & "www.mamma.com" & Chr(0x00)                     ; Host Name         www.mamma.com
  13.  
  14. ; Send Request to Proxy
  15. ConsoleWrite("! Request: " & Hex(BinaryString($sReq)) & @CR)
  16. TCPSend($hc,$sReq)
  17.  
  18. ; Wait for the Reply
  19. While 1
  20.     $sBuff = TCPRecv($hc,1)
  21.     If @error Then Exit @ScriptLineNumber
  22.     If StringLen($sBuff) > 0 Then ExitLoop
  23.     Sleep(100)
  24. WEnd
  25.  
  26. $sBuff &= TCPRecv($hc,8)
  27. ConsoleWrite("! Reply: " & Hex(BinaryString($sBuff)) & @CR)
  28.  
  29. ; Check for errors
  30. Switch StringMid(Hex(BinaryString($sBuff)),3,2)
  31.     Case "5A"
  32.         ConsoleWrite("> request granted" & @CR)
  33.     Case "5B"
  34.         ConsoleWrite("> request rejected or failed" & @CR)
  35.         Exit @ScriptLineNumber
  36.     Case "5C"
  37.         ConsoleWrite("> request failed because client is not running identd (or not reachable from the server)" & @CR)
  38.         Exit @ScriptLineNumber
  39.     Case "5D"
  40.         ConsoleWrite("> request failed because client's identd could not confirm the user id string in the request" & @CR)
  41.         Exit @ScriptLineNumber
  42. EndSwitch
  43.  
  44. ; Send Http Request to mamma and Search for "AutoIt"
  45. $sReq  = "GET /Mamma?query=AutoIt HTTP/1.0" & @CRLF & @CRLF
  46. ConsoleWrite("! Request:" & @CR & $sReq & "---------------------------------" & @CR)
  47. TCPSend($hc, $sReq)
  48.  
  49. ; Wait for the Reply
  50. ConsoleWrite("Receiving Data ")
  51. $sRepy = ''
  52. While 1
  53.     $sBuff = TCPRecv($hc,1024*5)
  54.     If @error Then ExitLoop
  55.     If StringLen($sBuff) > 0 Then
  56.         $sRepy &= $sBuff
  57.         ConsoleWrite(".")
  58.     EndIf
  59.     Sleep(100)
  60. WEnd
  61.  
  62. ; Parse Reply
  63. $iHeadEnd = StringInStr($sRepy, @CRLF & @CRLF) + 2
  64. $sRepyHead = StringMid($sRepy, 1, $iHeadEnd)
  65. $sRepyBody = StringMid($sRepy, $iHeadEnd)
  66.  
  67. ConsoleWrite(@CR & "! Reply:" & @CR & $sRepyHead & "---------------------------------" & @CR)
  68.  
  69. ; Save Result to disk
  70. $hFile = FileOpen("response.htm", 2)
  71. FileWrite($hFile, $sRepyBody)
  72. FileClose($hFile)
  73.  
  74. ConsoleWrite("Reply Body stored in .\response.htm (" & Round(StringLen($sRepyBody)/1024,2) & "Kb)" & @CR)
Add Comment
Please, Sign In to add comment