Post by garry » 25 Aug 2021, 07:25
hier noch 2 Beispiele
in diesem script beide benutzt für Test
Code: Select all
;-------- saved at Montag, 7. Juli 2014 08:15:52 --------------
;-------- https://autohotkey.com/board/topic/112151-checking-network-status/
;- CHECK internet connection & URL ------------------------------------------------
;urlx:="https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3" ;- correct
urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3" ;- correct
;urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1" ;- nicht correct aber umgeleitet
;urlx:="https://en.wikipediax.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1" ;- URL falsch not exist
;----
;urlx:="https://www.radio.de/s/hpr1classiccountry"
;urlx:="http://87.98.130.255:8188/stream" ;- HPR1 classic country
;urlx:="http://87.98.130.255:8188/played.html"
goto,example1
example1:
FLAG_ICC_FORCE_CONNECTION=1
if !DllCall("Wininet.dll\InternetGetConnectedState", "UInt*", flag, "UInt", 0)
{
aa1:= % "InternetGetConnectedState() failed " flag " " A_LastError
msgbox, 262208,NO SUCCES,AA1=%aa1%
return
}
flagstr =
if (flag & 0x01)
flagstr .= "INTERNET_CONNECTION_MODEM`n"
if (flag & 0x02)
flagstr .= "INTERNET_CONNECTION_LAN`n"
if (flag & 0x04)
flagstr .= "INTERNET_CONNECTION_PROXY`n"
if (flag & 0x10)
flagstr .= "INTERNET_RAS_INSTALLED`n"
if (flag & 0x20)
flagstr .= "INTERNET_CONNECTION_OFFLINE`n"
if (flag & 0x40)
flagstr .= "INTERNET_CONNECTION_CONFUGURED`n"
aa3:= % flagstr "InternetGetConnectedState() succeed " flag
if !DllCall("Wininet.dll\InternetCheckConnection", "Str",urlx,"UInt", FLAG_ICC_FORCE_CONNECTION, "UInt", 0)
{
aa2:= % "InternetCheckConnection() failed " A_LastError
msgbox, 262208,NO SUCCES,AA2=%aa2%
return
}
;msgbox,aa3=%aa3%
;return
example2:
;--- example for try/catch/error CHECK URL ------------------
xx:=ComObjCreate("WinHttp.WinHttpRequest.5.1") ;-Create the Object
;-- catch get error but don't show failure
;ComObjError(false)
;xx.Silent := True ;- script failure = off
xx.SetTimeouts(500,500,500,500)
try {
xx.Open("GET",urlx) ;-Open communication
xx.Send() ;-Send the "get" request
aac=
aac:=xx.ResponseText ;-Set the "aac" variable to the response
;msgbox, 262208,%urlx% exists,%aa4%`n`n%urlx%`n-----------------`n %aac%
} catch e {
xxx:=e.Message
msgbox, 262208,NO SUCCESS ERROR ,AA3=%aa3%`n------------`nError=Catch`n%urlx%`n NOT exists`n------------------------------------------`n%xxx%`n------------------------------------------,
return
}
msgbox, 262208,SUCCESS,AA3=%aa3%`n------------`nURL EXISTS=`n%urlx%
return
;==================================================================
hier noch 2 Beispiele
in diesem script beide benutzt für Test
[code];-------- saved at Montag, 7. Juli 2014 08:15:52 --------------
;-------- https://autohotkey.com/board/topic/112151-checking-network-status/
;- CHECK internet connection & URL ------------------------------------------------
;urlx:="https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3" ;- correct
urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3" ;- correct
;urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1" ;- nicht correct aber umgeleitet
;urlx:="https://en.wikipediax.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1" ;- URL falsch not exist
;----
;urlx:="https://www.radio.de/s/hpr1classiccountry"
;urlx:="http://87.98.130.255:8188/stream" ;- HPR1 classic country
;urlx:="http://87.98.130.255:8188/played.html"
goto,example1
example1:
FLAG_ICC_FORCE_CONNECTION=1
if !DllCall("Wininet.dll\InternetGetConnectedState", "UInt*", flag, "UInt", 0)
{
aa1:= % "InternetGetConnectedState() failed " flag " " A_LastError
msgbox, 262208,NO SUCCES,AA1=%aa1%
return
}
flagstr =
if (flag & 0x01)
flagstr .= "INTERNET_CONNECTION_MODEM`n"
if (flag & 0x02)
flagstr .= "INTERNET_CONNECTION_LAN`n"
if (flag & 0x04)
flagstr .= "INTERNET_CONNECTION_PROXY`n"
if (flag & 0x10)
flagstr .= "INTERNET_RAS_INSTALLED`n"
if (flag & 0x20)
flagstr .= "INTERNET_CONNECTION_OFFLINE`n"
if (flag & 0x40)
flagstr .= "INTERNET_CONNECTION_CONFUGURED`n"
aa3:= % flagstr "InternetGetConnectedState() succeed " flag
if !DllCall("Wininet.dll\InternetCheckConnection", "Str",urlx,"UInt", FLAG_ICC_FORCE_CONNECTION, "UInt", 0)
{
aa2:= % "InternetCheckConnection() failed " A_LastError
msgbox, 262208,NO SUCCES,AA2=%aa2%
return
}
;msgbox,aa3=%aa3%
;return
example2:
;--- example for try/catch/error CHECK URL ------------------
xx:=ComObjCreate("WinHttp.WinHttpRequest.5.1") ;-Create the Object
;-- catch get error but don't show failure
;ComObjError(false)
;xx.Silent := True ;- script failure = off
xx.SetTimeouts(500,500,500,500)
try {
xx.Open("GET",urlx) ;-Open communication
xx.Send() ;-Send the "get" request
aac=
aac:=xx.ResponseText ;-Set the "aac" variable to the response
;msgbox, 262208,%urlx% exists,%aa4%`n`n%urlx%`n-----------------`n %aac%
} catch e {
xxx:=e.Message
msgbox, 262208,NO SUCCESS ERROR ,AA3=%aa3%`n------------`nError=Catch`n%urlx%`n NOT exists`n------------------------------------------`n%xxx%`n------------------------------------------,
return
}
msgbox, 262208,SUCCESS,AA3=%aa3%`n------------`nURL EXISTS=`n%urlx%
return
;==================================================================
[/code]