youtuber

Url status check?

16 posts in this topic

How can I learn URLs status?

Global $aURL = "https://www.autoitscript.com"

Msgbox(0,"Status", "Status",_URLStatus($aURL))

Func _URLStatus($aURL)
   $objHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
   $objHTTP.Open("GET", $aURL, false)
   If $objHTTP.status = "200" Then
Msgbox(0,"Connection", "ok")
   Else
Msgbox(0,"Error", "Connection problem!")
   EndIf
EndFunc

 

Share this post


Link to post
Share on other sites



Global $aURL = "https://www.autoitscript.com"

Local $urlStatus = _URLStatus($aURL)
If $urlStatus <> 200 Then
    MsgBox(48, "Status", "Connection problem: " & $urlStatus & @CRLF & "URL: " & $aURL)
Else
    MsgBox(32, "Status", "Connection Successful!" & @CRLF & "URL: " & $aURL)
EndIf

Func _URLStatus($aURL)
    $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $oHTTP.Open("GET", $aURL, False)
    $oHTTP.Send()
    Return $oHTTP.Status = 200
EndFunc   ;==>_URLStatus

 


Regards,
 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@Trong Thanks for trying, but I think there's a problem!

Edited by youtuber

Share this post


Link to post
Share on other sites

It only works when there is an Internet connection and active URL!
I do not know how to ignore the error, I'm learning!


Regards,
 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Global $aURL = "https://www.autoitscript.com/forum/topic/asdf"

Local $urlStatus = _URLStatus($aURL)
If @error Then MsgBox(48, "Error: " & @error, "Connection problem: " & $urlStatus & @CRLF & "URL: " & $aURL)

Switch $urlStatus
    Case 200
        MsgBox(32, "Status: " & $urlStatus, "Connection Successful!" & @CRLF & "URL: " & $aURL)
    Case 404
        MsgBox(32, "Status: " & $urlStatus, "Connection Successful!" & @CRLF & "URL Not Found: " & $aURL)
    Case Else
        MsgBox(48, "Status: " & $urlStatus, "Connection problem!" & @CRLF & "URL: " & $aURL)
EndSwitch

Func _URLStatus($aURL)
    $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $oHTTP.Open("HEAD", $aURL, False)
    If @error Then Return SetError(1, 0, 0)
    $oHTTP.Send()
    If @error Then Return SetError(2, 0, 0)
    Return $oHTTP.Status
EndFunc   ;==>_URLStatus

 

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites

@Trong If you put a invalid URL it will give you a COM error, as advised by Mlipok, you should do something like this:

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $sURL = "https://www.autoitscriptABCD.com/forum/topic/asdf" ; Deliberately cause error by using a non-existing URL

For $i = 0 To 1
    Local $urlStatus = _URLStatus($sURL)
    If @error Then MsgBox(48, "Error: " & @error, "Connection problem: " & $urlStatus & @CRLF & "URL: " & $sURL)

    Switch $urlStatus
        Case 200
            MsgBox(32, "Status", "Connection Successful: " & $urlStatus & @CRLF & "URL: " & $sURL)
        Case 404
            MsgBox(32, "Status", "Connection Successful: " & $urlStatus & @CRLF & "URL Not Found: " & $sURL)
        Case Else
            MsgBox(48, "Status", "Connection problem: " & $urlStatus & @CRLF & "URL: " & $sURL)
    EndSwitch

    $sURL = "http://www.google.com" ; Lets use a valid URL now
Next

Func _URLStatus($sURL)
    $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $oHTTP.Open("HEAD", $sURL, False)
    If @error Then Return SetError(1, 0, 0)
    $oHTTP.Send()
    If @error Then Return SetError(2, 0, 0)
    Return $oHTTP.Status
EndFunc   ;==>_URLStatus

Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

Exit

By the way, its nice to see that you were seeking knowledge to be able to help someone else. :D

2 people like this

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Short final scripts:

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_COMErrFunc")

Global $aURL = "https://www.autoitscriptA.com/forum/topic/aloha"

Local $urlStatus = _URLStatus($aURL)
Switch $urlStatus
    Case 200
        MsgBox(32, "Status: " & $urlStatus, "Connection Successful!" & @CRLF & "URL: " & $aURL)
    Case 404
        MsgBox(32, "Status: " & $urlStatus, "Connection Successful!" & @CRLF & "URL Not Found: " & $aURL)
    Case 105
        MsgBox(48, "Status: " & $urlStatus, "Connection error: ERR_NAME_NOT_RESOLVED" & @CRLF & "URL is Not Found: " & $aURL)
    Case Else
        MsgBox(48, "Status: " & $urlStatus, "Connection error!" & @CRLF & "URL: " & $aURL)
EndSwitch

Func _URLStatus($aURL)
    $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $oHTTP.Open("HEAD", $aURL, False)
    If @error Then Return SetError(1, 0, 0)
    $oHTTP.Send()
    If @error Then Return SetError(2, 0, 105) ;Error 105 (net::ERR_NAME_NOT_RESOLVED)
    Local $oStatus = $oHTTP.Status
    If @error Then Return SetError(3, 0, 118) ;Error 118 (net::ERR_CONNECTION_TIMED_OUT)
;~  $oErrorHandler = 0
    Return $oStatus
EndFunc   ;==>_URLStatus

Func _COMErrFunc()
    ; Do nothing special, just check @error after suspect functions.
EndFunc   ;==>_COMErrFunc

 

Edited by Trong
same time, duplicate!

Regards,
 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Why you mixing Local and Global statement at the same scope level ?

Global $aURL = "https://www.autoitscriptA.com/forum/topic/aloha"
Local $urlStatus = _URLStatus($aURL)

 


Here is better example:

#include <MsgBoxConstants.au3>
_Example("https://www.somenotexistingurl.com")

Func _Example($sURL)
    Local $sURL_Status = _ULRNotifier(_URL_CheckStatus($sURL))
    If @error Then Return SetError(@error, @extended, $sURL_Status)

    MsgBox($MB_OK + $MB_ICONINFORMATION, 'SUCCESS', '$sURL_Status=' & $sURL_Status)

EndFunc   ;==>_Example

Func _URL_CheckStatus($sURL)
    _URLChecker_COMErrDescripion("")
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_URLChecker_COMErrFunc")

    $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

    $oHTTP.Open("HEAD", $sURL, False)
    If @error Then Return SetError(1, @error, 0)

    $oHTTP.Send()
    If @error Then Return SetError(2, @error, 105) ;Error 105 (net::ERR_NAME_NOT_RESOLVED)

    Local $sStatus = $oHTTP.Status
    If @error Then Return SetError(3, @error, 118) ;Error 118 (net::ERR_CONNECTION_TIMED_OUT)

    Return $sStatus
EndFunc   ;==>_URL_CheckStatus

Func _URLChecker_COMErrFunc($oError)
    _URLChecker_COMErrDescripion($oError.description)

    Return ; you can comment/dlete this return to show full error descripition

    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "$oError.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "$oError.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "$oError.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "$oError.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "$oError.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "$oError.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "$oError.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "$oError.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "$oError.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_URLChecker_COMErrFunc

Func _URLChecker_COMErrDescripion($sDescription = Default)
    Local Static $sDescription_static = ''
    If $sDescription <> Default Then $sDescription_static = $sDescription
    Return $sDescription_static
EndFunc   ;==>_URLChecker_COMErrDescripion

Func _ULRNotifier($vResult, $iError = @error, $iExtended = @extended)
    If $iError Then ConsoleWrite( _
            "! @error = " & $iError & "  @extended = " & $iExtended & " $vResult = " & $vResult & @CRLF & _
            "! " & _URLChecker_COMErrDescripion() & @CRLF _
            )
    Return SetError($iError, $iExtended, $vResult)
EndFunc   ;==>_ULRNotifier

 

Edited by mLipok
1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites
55 minutes ago, mLipok said:

Why you mixing Local and Global statement at the same scope level ?

Global $aURL = "https://www.autoitscriptA.com/forum/topic/aloha"
Local $urlStatus = _URLStatus($aURL)

 

better ?
 

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_COMErrFunc")

Global $sURL = "https://www.autoitscriptA.com/forum/topic/aloha"

Global $urlStatus = _URLStatus($sURL)

Switch $urlStatus
    Case 200
        MsgBox(32, "Status: " & $urlStatus, "Connection Successful!" & @CRLF & "URL: " & $sURL)
    Case 404
        MsgBox(32, "Status: " & $urlStatus, "Connection Successful!" & @CRLF & "URL Not Found: " & $sURL)
    Case 105
        MsgBox(48, "Status: " & $urlStatus, "Connection error: ERR_NAME_NOT_RESOLVED" & @CRLF & "URL is Not Found: " & $sURL)
    Case Else
        MsgBox(48, "Status: " & $urlStatus, "Connection error!" & @CRLF & "URL: " & $sURL)
EndSwitch

Func _URLStatus($aURL)
    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $oHTTP.Open("HEAD", $aURL, False)
    If @error Then Return SetError(1, @error, 0)
    $oHTTP.Send()
    If @error Then Return SetError(2, @error, 105) ;Error 105 (net::ERR_NAME_NOT_RESOLVED)
    Local $oStatus = $oHTTP.Status
    If @error Then Return SetError(3, @error, 118) ;Error 118 (net::ERR_CONNECTION_TIMED_OUT)
;~  $oErrorHandler = 0
    Return $oStatus
EndFunc   ;==>_URLStatus

Func _COMErrFunc()
    ; Do nothing special, just check @error after suspect functions.
EndFunc   ;==>_COMErrFunc

 


Regards,
 

Share this post


Link to post
Share on other sites
11 minutes ago, Trong said:

better ?

Better is post #9 :P

But the following one :

Opt("MustDeclareVars", 1)
#AutoIt3Wrapper_Run_AU3Check=Y
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

#include <MsgBoxConstants.au3>
_Example("https://www.somenotexistingurl.com")

Func _Example($sURL)
    Local $sURL_Status = _ULRNotifier(_URL_CheckStatus($sURL))
    If @error Then Return SetError(@error, @extended, $sURL_Status)

    MsgBox($MB_OK + $MB_ICONINFORMATION, 'SUCCESS', '$sURL_Status=' & $sURL_Status)

EndFunc   ;==>_Example

Func _URL_CheckStatus($sURL)
    _URLChecker_COMErrDescripion("")
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_URLChecker_COMErrFunc")
    #forceref $oErrorHandler

    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

    $oHTTP.Open("HEAD", $sURL, False)
    If @error Then Return SetError(1, @error, '')

    $oHTTP.Send()
    Local $iError = @error

    Local $sStatus = $oHTTP.Status
    If @error Then Return SetError(3, @error, $sStatus)

    If $iError Then Return SetError(2, $iError, $sStatus)

    Return $sStatus
EndFunc   ;==>_URL_CheckStatus

Func _URLChecker_COMErrFunc($oError)
    _URLChecker_COMErrDescripion($oError.description)

    Return ; you can comment/dlete this return to show full error descripition

    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "$oError.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "$oError.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "$oError.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "$oError.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "$oError.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "$oError.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "$oError.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "$oError.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "$oError.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_URLChecker_COMErrFunc

Func _URLChecker_COMErrDescripion($sDescription = Default)
    Local Static $sDescription_static = ''
    If $sDescription <> Default Then $sDescription_static = $sDescription
    Return $sDescription_static
EndFunc   ;==>_URLChecker_COMErrDescripion

Func _ULRNotifier($vResult, $iError = @error, $iExtended = @extended)
    If $iError Then ConsoleWrite( _
            "! @error = " & $iError & "  @extended = " & $iExtended & " $vResult = " & $vResult & @CRLF & _
            "! " & _URLChecker_COMErrDescripion() & @CRLF _
            )
    Return SetError($iError, $iExtended, $vResult)
EndFunc   ;==>_ULRNotifier

is the best - at least for the moment when I post it ;)

 

 

 

2 people like this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Is it true my code accordingly?

#include <Inet.au3>
#include <String.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_COMErrFunc")
Global $sURL = "https://www.google.com"
Global $urlStatus = _URLStatus($sURL)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 452, 282, 33, 105)
$Edit1 = GUICtrlCreateEdit("", 32, 32, 185, 241)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Run", 320, 16, 75, 25)
$Edit2 = GUICtrlCreateEdit("", 232, 88, 169, 177)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $aproxyread = StringSplit(GUICtrlRead($Edit1), @CR)
            For $aproxyadd = 1 To UBound($aproxyread) - 1
                Sleep(800)
                HttpSetProxy(2, $aproxyread[$aproxyadd])
  Switch $urlStatus
      Case 200
  GUICtrlSetData($Edit2, "Proxy: " & $aproxyread[$aproxyadd] & @CRLF & "IP: " & _IPGet())
      Case Else
          HttpSetProxy(2, $aproxyread[$aproxyadd], @CR)
       GUICtrlSetData($Edit2, "Proxy: " & $aproxyread[$aproxyadd] & @CRLF & "IP: " & _IPGet())
 EndSwitch
   Next
    EndSwitch
WEnd

Func _IPGet()
    Local Const $GETIP_TIMER = 3000
    Local Static $hTimer = 0
    Local Static $sLastIP = 0
    If TimerDiff($hTimer) < $GETIP_TIMER And Not $sLastIP Then
        Return SetExtended(1, $sLastIP)
    EndIf
    Local $aGetIPURL[] = ["http://bot.whatismyipaddress.com", "http://www.myexternalip.com/raw", "http://checkip.dyndns.org"], $aReturn = 0, $sReturn = ""
    For $i = 1 To UBound($aGetIPURL) - 1
        $sReturn = InetRead($aGetIPURL[$i])
        If @error Or $sReturn == "" Then ContinueLoop
        $aReturn = StringRegExp(BinaryToString($sReturn), "((?:\d{1,3}\.){3}\d{1,3})", 3)
        If Not @error Then
            $sReturn = $aReturn[0]
            ExitLoop
        EndIf
        $sReturn = ""
    Next
    $hTimer = TimerInit()
    $sLastIP = $sReturn
    If $sReturn == "" Then Return SetError(1, 0, -1)
    Return $sReturn
EndFunc   ;==>_IPGet


Func _URLStatus($aURL)
    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $oHTTP.Open("HEAD", $aURL, False)
    If @error Then Return SetError(1, @error, 0)
    $oHTTP.Send()
    If @error Then Return SetError(2, @error, 105) ;Error 105 (net::ERR_NAME_NOT_RESOLVED)
    Local $oStatus = $oHTTP.Status
    If @error Then Return SetError(3, @error, 118) ;Error 118 (net::ERR_CONNECTION_TIMED_OUT)
;~  $oErrorHandler = 0
    Return $oStatus
EndFunc   ;==>_URLStatus

Func _COMErrFunc()
    ; Do nothing special, just check @error after suspect functions.
EndFunc   ;==>_COMErrFunc

 

<snip>

Edited by JLogan3o13

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Help please

if The proxy does not work 
skip the line
How?

Case $Button1
            $aproxyread = StringSplit(GUICtrlRead($Edit1), @CR)
            For $aproxyadd = 1 To UBound($aproxyread) - 1
                Sleep(800)
                HttpSetProxy(2, $aproxyread[$aproxyadd])
             Switch $urlStatus
           Case 200
        GUICtrlSetData($Edit2, "Proxy: " & $aproxyread[$aproxyadd] & @CRLF & "IP: " & _IPGet())
          ;------------------------------------------------------------------------------------
          Case Else
          HttpSetProxy(2, $aproxyread[$aproxyadd], @CR);Is this the correct code to bypass the proxy?

 

Edited by youtuber

Share this post


Link to post
Share on other sites

@youtuber please upload your text file again if you intended it to be in the post, the link became corrupted.

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Don't PM for ask or request help! All problem, please post here!

#include <Inet.au3>
#include <String.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_COMErrFunc")
Global $sURL = "https://www.google.com"
Global $sListProxy, $sIP
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 452, 282, 33, 105)
Global $Edit1 = GUICtrlCreateEdit("", 32, 32, 185, 241)
GUICtrlSetData(-1, "")
Global $Button1 = GUICtrlCreateButton("Run", 320, 16, 75, 25)
Global $Edit2 = GUICtrlCreateEdit("", 232, 88, 169, 177)
GUICtrlSetData(-1, "")
Global $Label1 = GUICtrlCreateLabel("", 232, 64, 164, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            $sListProxy = ""
            $aproxyread = StringSplit(GUICtrlRead($Edit1), @CR)
            For $aproxyadd = 1 To UBound($aproxyread) - 1
                GUICtrlSetData($Label1, "Set Proxy: " & $aproxyread[$aproxyadd])
                HttpSetProxy(2, $aproxyread[$aproxyadd])
                If _URLStatus($sURL) = 200 Then
                    GUICtrlSetData($Label1, "Getting IP......")
                    $sIP = _IPGet()
                    If StringInStr($sIP, ".") Then GUICtrlSetData($Label1, "Get IP sucsses!")
                    $sListProxy &= "Proxy: " & $aproxyread[$aproxyadd] & @CRLF & "Cur IP: " & $sIP & @CRLF & @CRLF
                    GUICtrlSetData($Edit2, $sListProxy)
                EndIf
                Sleep(500)
                GUICtrlSetData($Label1, "")
            Next
    EndSwitch
WEnd

Func _IPGet()
    Local $aGetIPURL[] = ["http://www.myexternalip.com/raw", "http://bot.whatismyipaddress.com", "http://checkip.dyndns.org"], $aReturn = 0, $sReturn = ""
    For $i = 1 To UBound($aGetIPURL) - 1
        $sReturn = InetRead($aGetIPURL[$i])
        If @error Or $sReturn == "" Then ContinueLoop
        $aReturn = StringRegExp(BinaryToString($sReturn), "((?:\d{1,3}\.){3}\d{1,3})", 3)
        If Not @error Then
            $sReturn = $aReturn[0]
            ExitLoop
        EndIf
        $sReturn = ""
    Next
    If $sReturn == "" Then Return SetError(1, 0, -1)
    Return $sReturn
EndFunc   ;==>_IPGet


Func _URLStatus($aURL)
    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
    $oHTTP.Open("HEAD", $aURL, False)
    If @error Then Return SetError(1, @error, 0)
    $oHTTP.Send()
    If @error Then Return SetError(2, @error, 105) ;Error 105 (net::ERR_NAME_NOT_RESOLVED)
    Local $oStatus = $oHTTP.Status
    If @error Then Return SetError(3, @error, 118) ;Error 118 (net::ERR_CONNECTION_TIMED_OUT)
;~  $oErrorHandler = 0
    Return $oStatus
EndFunc   ;==>_URLStatus

Func _COMErrFunc()
    ; Do nothing special, just check @error after suspect functions.
EndFunc   ;==>_COMErrFunc

 

 

If only check Proxy, use this function:

 

TCPStartup()
OnAutoItExitRegister("TCPShutdown")
Func _CheckProxy($iProxy)
    If Not StringInStr($iProxy, ":") Then Return SetError(1, 0, 0)
    Local $iSocket = 0, $xSocket = StringSplit($iProxy, ":", 1)
    If IsArray($xSocket) Then
        If $xSocket[0] = 2 Then
            $iSocket = TCPConnect($xSocket[1], $xSocket[2])
            If Not @error Then
                TCPCloseSocket($iSocket)
                Return 1
            EndIf
        EndIf
    EndIf
    Return 0
EndFunc   ;==>_CheckProxy

 


Regards,
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now