Advertisement
Guest User

proxy

a guest
Sep 10th, 2013
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. #include "WinHttp.au3"
  2. #include <Array.au3>
  3. #include <WinAPI.au3>
  4.  
  5. Opt("MustDeclareVars", 1)
  6.  
  7. ; Open needed handles
  8. Local $arr = _WinHttpGetIEProxyConfigForCurrentUser()
  9.  
  10. Local $hOpen = ""
  11.  
  12. If $arr[1] <> '' Then
  13. $hOpen = _WinHttpOpen(Default, 1, $arr[1])
  14. Else
  15. $hOpen = _WinHttpOpen()
  16. EndIf
  17.  
  18. Local $hConnect = _WinHttpConnect($hOpen, "whatismyipaddress.com")
  19. ; Specify the reguest:
  20. Local $hRequest = _WinHttpOpenRequest($hConnect)
  21.  
  22. _WinHttpGetProxyForUrl($hOpen, "whatismyipaddress.com", "http://rosinstrument.com/cgi-bin/proxy.pac")
  23. ; Send request
  24. _WinHttpSendRequest($hRequest, "User-Agent: Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.16")
  25.  
  26. ; Wait for the response
  27. _WinHttpReceiveResponse($hRequest)
  28.  
  29. Local $sHeader = _WinHttpReadData($hRequest) ; ...get full header
  30. While @extended == 8192
  31. $sHeader &= _WinHttpReadData($hRequest) ; ...get full header
  32. WEnd
  33.  
  34. ; Clean
  35. _WinHttpCloseHandle($hRequest)
  36. _WinHttpCloseHandle($hConnect)
  37. _WinHttpCloseHandle($hOpen)
  38.  
  39. ; Display retrieved header
  40. If $sHeader == "" Then
  41. MsgBox(0, "", "Dupa")
  42. Else
  43. MsgBox(0, "Is proxy used?", StringInStr($sHeader, "78&#46;30&#46;93&#46;188") == 0)
  44. ClipPut($sHeader)
  45. EndIf
  46.  
  47. Exit
  48.  
  49. Func _WinHttpGetProxyForUrl($handle, $url, $pacAddress)
  50. Local $WINHTTP_AUTOPROXY_OPTIONS = DllStructCreate("dword dwFlags;" & _
  51. "dword dwAutoDetectFlags;" & _
  52. "ptr lpszAutoConfigUrl;" & _
  53. "ptr lpvReserved;" & _
  54. "dword dwReserved;" & _
  55. "dword fAutoLogonIfChallenged;")
  56. ConsoleWrite("Error = " & @error & @CRLF)
  57. Local $WINHTTP_PROXY_INFO = DllStructCreate("dword AccessType;" & _
  58. "ptr Proxy;" & _
  59. "ptr ProxyBypass")
  60. ConsoleWrite("Error = " & @error & @CRLF)
  61.  
  62. DllStructSetData($WINHTTP_AUTOPROXY_OPTIONS, "dwFlags", $WINHTTP_AUTOPROXY_CONFIG_URL)
  63. DllStructSetData($WINHTTP_AUTOPROXY_OPTIONS, "dwAutoDetectFlags", BitOR($WINHTTP_AUTO_DETECT_TYPE_DHCP, $WINHTTP_AUTO_DETECT_TYPE_DNS_A))
  64. Local $tPacAddress = DllStructCreate("wchar[" & StringLen($pacAddress) + 1 & "]")
  65. DllStructSetData($tPacAddress, 1, $pacAddress)
  66. ConsoleWrite("Error = " & @error & @CRLF)
  67. DllStructSetData($WINHTTP_AUTOPROXY_OPTIONS, "lpszAutoConfigUrl", DllStructGetPtr($tPacAddress))
  68.  
  69. Local $tUrl = DllStructCreate("wchar[" & StringLen($url) + 1 & "]")
  70. DllStructSetData($tUrl, 1, $url)
  71.  
  72. Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpGetProxyForUrl", "handle", $handle, _
  73. "wstr", $url, _
  74. "struct*", DllStructGetPtr($WINHTTP_AUTOPROXY_OPTIONS), _
  75. "struct*", DllStructGetPtr($WINHTTP_PROXY_INFO))
  76.  
  77. ConsoleWrite(_WinAPI_GetLastError())
  78.  
  79. Local $pProxy = DllStructGetData($WINHTTP_PROXY_INFO, "Proxy")
  80. Return DllStructGetData(DllStructCreate("wchar[" & _WinAPI_StringLenW($pProxy) & "]", $pProxy), 1)
  81. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement