Search the Community
Showing results for tags 'Test internet connection'.
-
This is a method to test connectivity to the Internet using the same approach as Mircosoft does, therefore no need to contact third party sites such as google or bing, which has often been the case. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MicrosoftInternetConnectivity ; Description ...: Test if the local machine is connected to the Internet using the same method as Microsoft for 'network awareness' minus the dns records verification. ; Syntax ........: _MicrosoftInternetConnectivity() ; Parameters ....: None ; Return values .: Success: True ; Failure: False ; Author ........: guinness ; Remarks .......: This will contact the website www.msftncsi.com. Works with Windows 2000+ ; Requires TCPStartup() to be initialised. ; The function has a restriction of contacting Microsoft every 15 seconds, so if you call the function within a tight loop then the last response will ; be returned and @extended set to non-zero. ; Link ..........: http://technet.microsoft.com/en-us/library/cc766017(v=ws.10).aspx#BKMK_How ; Example .......: Yes ; =============================================================================================================================== Func _MicrosoftInternetConnectivity() Local Static $hTimer = 0, _ ; Create a static variable to store the timer handle. $bLastResponse = Null ; Create a static variable to store the last response. If TimerDiff($hTimer) < 15000 And Not ($bLastResponse = Null) Then ; If still in the timer and $bLastResponse contains a value. Return SetExtended(1, $bLastResponse) ; Return the last response instead and set @extended to 1. EndIf Local $bEnableActiveProbing = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'EnableActiveProbing') > 0 If @error Then $bEnableActiveProbing = True EndIf If Not $bEnableActiveProbing Then Return False EndIf Local $sContent = 'Microsoft NCSI', _ $sDNSHost = 'dns.msftncsi.com', _ $sDNSIPAddress = '131.107.255.255', _ $sURL = 'http://' & RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbeHost') & '/' & RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbePath') If $sURL == 'http:///' Then $sURL = 'http://www.msftncsi.com/ncsi.txt' Else $sContent = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbeContent') $sDNSIPAddress = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveDnsProbeContent') $sDNSHost = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveDnsProbeHost') EndIf $bLastResponse = BinaryToString(InetRead($sURL, $INET_FORCERELOAD)) == $sContent And TCPNameToIP($sDNSHost) == $sDNSIPAddress Return $bLastResponse EndFunc ;==>_MicrosoftInternetConnectivity Example use of Function: #include <InetConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() TCPStartup() Local $bConnected = _MicrosoftInternetConnectivity() MsgBox($MB_SYSTEMMODAL, '', 'Is the Internet working?: ' & ($bConnected ? 'Yes, the Internet is working.' : 'No, the Internet isn''t working.')) TCPShutdown() EndFunc ;==>Example