Search the Community
Showing results for tags 'download speed'.
-
Hi to all, today i needed at work a script that allow me to test our new servers. So i needed a simple software that allow me to test our internet download speed and upload speed. So i have decided to write an UDF, and i want to share that with the community. Thanks to www.speedtest.net and www.ip-tracker.org for their great service! This is my first UDF that i publish here, so don't be too bad with me If you have found a bug, have a suggestion, or want other functtion please tell me Changelog v.1.1.0 (13/03/2013) Added _NetInfo_GetWhois Added _NetInfo_NameToIP Added _NetInfo_IPToName Added _NetInfo_GetLocalDNS Code Improvement ;===================================================== v.1.0.1 (12/03/2013) Fixed some variables ;Thanks to Exit for bug report ;===================================================== v.1.0.0 (12/03/2013) Initial Release Here is a simple Example of usage: #include <NetInfo.au3> ;This test can take 2~3 minutes be patient! ;NetInfo_GetDownloadSpeed will find for you only the test server in your state ;_NetInfo_GetDownloadSpeed have different test with different file size (and time execution) for an "accurate" test use the biggest file! _NetInfo_GetDownloadSpeed(9) ;If you want to test you connection with server of different state just add the country code in the function _NetInfo_GetDownloadSpeed(7,"US") $Download_Speed = _NetInfo_GetDownloadSpeed() ;If you want to test you upload with server of different state just add the country code in the function _NetInfo_GetUploadSpeed("US") $Upload_Speed = _NetInfo_GetUploadSpeed() ;If you want to test you upload with server of different state just add the country code in the function _NetInfo_GetLatency("US") $Internet_Latency = _NetInfo_GetLatency() $My_Hostname = _NetInfo_GetHostname() $My_Location = _NetInfo_GetIPLocation() ;This offcourse is not accurate ;) $My_ISP = _NetInfo_GetISP() $result = "Your Peak download speed is: " & $Download_Speed[0] & " kB/s" & @CRLF & _ "Your Average download speed is: " & $Download_Speed[1] & " kB/s" & @CRLF & _ "Your Average upload speed is: " & $Upload_Speed & " kB/s" & @CRLF & _ "Your Wrost latency time is: " & $Internet_Latency[0] & " ms" & @CRLF & _ "Your Average latency time is: " & $Internet_Latency[1] & " ms" & @CRLF & _ "=========================================================" & @CRLF & _ "Your Hostname is: " & $My_Hostname & @CRLF & _ "Your Country Code is: " & $My_Location[0] & @CRLF & _ "Your State is: " & $My_Location[1] & @CRLF & _ "Your Longitude is: " & $My_Location[2] & @CRLF & _ "Your Latitude is: " & $My_Location[3] & @CRLF & _ "Your ISP is: " & $My_ISP MsgBox(0, "Here is the result", $result) $WhoIS = _NetInfo_GetWhois("autoitscript.com") ;You have to insert as parameter only the url domain ex: "autoit.com". Complete url like "http://www.autoit.com" ;or "www.autoit.com", etc are NOT allowed. MsgBox(0, "autoitscript.com WHOIS", $WhoIS) $System_DNS = _NetInfo_GetLocalDNS() $DNS_txt = "" For $i = 0 To UBound($System_DNS) - 1 $DNS_txt &= $System_DNS[$i] & @CRLF Next MsgBox(0,"Your local DNS", $DNS_txt) $NameToIP = _NetInfo_NameToIP("hiddensoft.com") MsgBox(0,"Info", "hiddensoft.com IP: " & @CRLF & $NameToIP) $IPToName = _NetInfo_IPToName($NameToIP) MsgBox(0,"Info", "Did you know that hiddensoft.com ip: " & $NameToIP & " is also the ip of: " & $IPToName & " ? ;)") Here is the UDF: Thanks to: Exit for a bug report #include-once #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 Global $__gServer = "" ; #INDEX# ======================================================================================================================= ; Title .........: NetInfo v.1.1.0 ; AutoIt Version : v3.3.8.1 ; Description ...: An UDF to retrive usefull info about your internet connection ; Author(s) .....: Nessie ; =============================================================================================================================== ; #INCLUDES# ========================================================================================================= ; None ; #GLOBAL VARIABLES# ================================================================================================= ; $__gServer ; #CURRENT# ===================================================================================================================== ;_NetInfo_GetDownloadSpeed ;_NetInfo_GetUploadSpeed ;_NetInfo_GetLatency ;_NetInfo_GetHostname ;_NetInfo_GetIPLocation ;_NetInfo_GetISP ;_NetInfo_GetWhois ;_NetInfo_NameToIP ;_NetInfo_IPToName ;_NetInfo_GetLocalDNS ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ;__NetInfo_GetCountryCode ;__NetInfo_GetServerList ;__NetInfo_RandomText ;__NetInfo_HTTP_Post ;__NetInfo_HTTP_Get ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_GetDownloadSpeed ; Description ...: Return the internet download speed ; Syntax.........: _NetInfo_GetDownloadSpeed([[$i_Size =7] [, $s_CountryCode = 0]]) ; Parameters ....: $i_Size - An interger [0-9] ID where you can select the file download size ; 0 - Download an image with 350x350 resolution and 240KB file size ; 1 - Download an image with 500x500 resolution and 494KB file size ; 2 - Download an image with 750x750 resolution and 1.1MB file size ; 3 - Download an image with 1000x1000 resolution and 1.9MB file size ; 4 - Download an image with 1500x1500 resolution and 4.3MB file size ; 5 - Download an image with 2000x2000 resolution and 7.5MB file size ; 6 - Download an image with 2500x2500 resolution and 12MB file size ; 7 - Download an image with 3000x3000 resolution and 17MB file size ; 8 - Download an image with 3500x3500 resolution and 23MB file size ; 9 - Download an image with 4000x4000 resolution and 30MB file size ; $s_CountryCode - The ISO 3166-1 country code of the desidered test server ; Return values .: On Success - ; $array[0] = Peak Speed Value (kB/s) ; $array[1] = Average Download Speed (kB/s) ; On Failure - ; @error = 1 Wrong Size Test ID ; @error = 2 Wrong Country Code ; @error = 3 Unable to get server list ; @error = 4 Other Error ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_GetDownloadSpeed($i_Size = 7, $s_CountryCode = "") If $i_Size < 0 Or $i_Size > 9 Then SetError(1, 0, "") If $s_CountryCode <> "" And StringLen($s_CountryCode) <> 2 Then Return SetError(2, 0, "") Local $aReturn[2], $_InfoData, $iBytes_read_1, $iBytes_read_2, $iPeak If $s_CountryCode = "" Then $s_CountryCode = __NetInfo_GetCountryCode() If @error Then $s_CountryCode = "US" EndIf EndIf If $__gServer = "" Then $__gServer = __NetInfo_GetServerList($s_CountryCode) If @error Then Return SetError(3, 0, "") EndIf Local $aResolution[10] = ['350x350', '500x500', '750x750', '1000x1000', '1500x1500', '2000x2000', '2500x2500', '3000x3000', '3500x3500', '4000x4000'] Local $sTemp = @TempDir & "\SpeedTest_Download.dat" Local $hFile = InetGet($__gServer & "random" & $aResolution[$i_Size] & ".jpg", $sTemp, 1, 1) Local $iBegin = TimerInit() Do $_InfoData = InetGetInfo($hFile) If @error Then SetError(4, 0, "") $iBytes_read_1 = $_InfoData[0] Sleep(1000) $_InfoData = InetGetInfo($hFile) If @error Then SetError(4, 0, "") $iBytes_read_2 = $_InfoData[0] Local $iDown_Speed = Int(($iBytes_read_2 - $iBytes_read_1) / 1024) If $iDown_Speed > $iPeak Then $iPeak = $iDown_Speed EndIf Until $_InfoData[2] = True Local $iEnd = TimerDiff($iBegin) FileDelete($sTemp) $aReturn[0] = $iPeak $aReturn[1] = Int($_InfoData[1] / $iEnd) ;Average Speed Return $aReturn EndFunc ;==>_NetInfo_GetDownloadSpeed ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_GetUploadSpeed ; Description ...: ; Syntax.........: _NetInfo_GetUploadSpeed([$s_CountryCode=""]) ; Parameters ....: $s_CountryCode - The ISO 3166-1 country code of the desidered test server ; Return values .: On Success - Return the Average upload speed (kB/s) ; On Failure - ; @error = 1 Unable to get server list ; @error = 2 Unable to contact the server ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_GetUploadSpeed($s_CountryCode = "") If $s_CountryCode <> "" And StringLen($s_CountryCode) <> 2 Then Return SetError(2, 0, "") If $s_CountryCode = "" Then $s_CountryCode = __NetInfo_GetCountryCode() If @error Then $s_CountryCode = "US" EndIf EndIf Local $iBegin = TimerInit() Local $iRandom = Random(100000000000, 9999999999999, 1) If $__gServer = "" Then $__gServer = __NetInfo_GetServerList($s_CountryCode) If @error Then Return SetError(1, 0, "") EndIf __NetInfo_HTTP_Post($__gServer & "upload.php?0." & $iRandom, __NetInfo_RandomText()) If @error Then SetError(2, 0, "") Local $iEnd = TimerDiff($iBegin) Local $iRet = Int(($iEnd * 1000) / 499999) Return $iRet EndFunc ;==>_NetInfo_GetUploadSpeed ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_GetLatency ; Description ...: Return the internet latency in milliseconds ; Syntax.........: ([$s_CountryCode=""]) ; Parameters ....: $s_CountryCode - The ISO 3166-1 country code of the desidered test server ; Return values .: On Success - Returns the internet latency in milliseconds ; $array[0] = Wrost Latency Value ; $array[1] = Average Latency (between 5 test) ; On Failure - Returns -1 and sets @error to non-zero. ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_GetLatency($s_CountryCode = "") If $s_CountryCode <> "" And StringLen($s_CountryCode) <> 2 Then Return SetError(2, 0, "") Local $aReturn[2], $iBegin, $iEnd, $iWrost = 0, $iAverage If $s_CountryCode = "" Then $s_CountryCode = __NetInfo_GetCountryCode() If @error Then $s_CountryCode = "US" EndIf EndIf If $__gServer = "" Then $__gServer = __NetInfo_GetServerList($s_CountryCode) If @error Then Return SetError(1, 0, "") EndIf Local $iRandom = Random(100000000000, 9999999999999, 1) For $i = 1 To 5 $iBegin = TimerInit() __NetInfo_HTTP_Get($__gServer & "latency.txt?x=" & $iRandom, "") If @error Then SetError(1, 0, -1) $iEnd = TimerDiff($iBegin) $iAverage += $iEnd If $iEnd > $iWrost Then $iWrost = Round($iEnd, 2) EndIf Next $aReturn[0] = $iWrost $aReturn[1] = Round($iAverage / 5, 2) Return $aReturn EndFunc ;==>_NetInfo_GetLatency ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_GetHostname ; Description ...: Retrive the Hostname of current IP ; Syntax.........: _NetInfo_GetHostname() ; Return values .: On Success - Returns the Host Name ; On Failure - Returns 0 and sets @error to non-zero. ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_GetHostname() Local $bRead, $sRead $bRead = InetRead("http://www.ip-tracker.org/track-ip-api.php") $sRead = BinaryToString($bRead) Local $aReturn = StringRegExp($sRead, 'Your Hostname: <b>(.*?)</b>', 3) If @error Then Return SetError(1, 0, 0) Return $aReturn[0] EndFunc ;==>_NetInfo_GetHostname ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_GetIPLocation ; Description ...: Retrive the location of current IP ; Syntax.........: _NetInfo_GetIPLocation() ; Return values .: On Success - ; $array[0] = Country Code ; $array[1] = State ; $array[2] = Longitude ; $array[3] = Latitude ; On Failure - ; @error = 1 Unable to resolve IP ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_GetIPLocation() Local $aReturn[4], $bRead, $sRead, $aRegex $bRead = InetRead("http://www.ip-tracker.org/track-ip-api.php") $sRead = BinaryToString($bRead) $aRegex = StringRegExp($sRead, '<b>(.*?)</b>', 3) If UBound($aRegex) - 1 <> 7 Then Return SetError(1, 0, "") $aReturn[0] = $aRegex[0] $aReturn[1] = $aRegex[1] $aReturn[2] = $aRegex[4] $aReturn[3] = $aRegex[5] Return $aReturn EndFunc ;==>_NetInfo_GetIPLocation ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_GetISP ; Description ...: Retrive the user ISP (Internet Provider) ; Syntax.........: _NetInfo_GetISP() ; Return values .: On Success - Return the ISP name ; On Failure - Returns 0 and sets @error to non-zero. ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_GetISP() Local $aReturn, $bRead, $sRead $bRead = InetRead("http://www.ip-tracker.org/track-ip-api.php") $sRead = BinaryToString($bRead) $aReturn = StringRegExp($sRead, 'Your ISP: <b>(.*?)</b>', 3) If @error Then Return SetError(1, 0, 0) Return $aReturn[0] EndFunc ;==>_NetInfo_GetISP ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_GetWhois ; Description ...: Retrive the domain whois ; Syntax.........: _NetInfo_GetWhois($domain) ; Remarks .......: You have to insert as parameter only the url domain ex: "autoit.com". Complete url like "http://www.autoit.com" ; or "www.autoit.com", etc are NOT allowed. ; Return values .: On Success - Return the domain Whois ; On Failure - Returns 0 and sets @error to non-zero. ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_GetWhois($s_Domain) Local $aReturn, $bRead, $sRead $bRead = InetRead("http://whoiz.herokuapp.com/lookup?url=" & $s_Domain) $sRead = BinaryToString($bRead) $aReturn = StringRegExp($sRead, "(?s)<pre class='content'>(.*?)</div>", 3) If @error Then Return SetError(1, 0, 0) Return $aReturn[0] EndFunc ;==>_NetInfo_GetWhois ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_NameToIP ; Description ...: Converts an Internet name to IP address. ; Syntax.........: _NetInfo_NameToIP($domain) ; Remarks .......: You have to insert as parameter only the url domain ex: "autoit.com". Complete url like "http://www.autoit.com" ; or "www.autoit.com", etc are NOT allowed. ; Return values .: On Success - Returns string containing IP address corresponding to the name ; On Failure - Returns "" and set @error. ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_NameToIP($s_Domain) TCPStartup() Local $aResult = TCPNameToIP($s_Domain) If @error Then Return SetError(1, 0, "") TCPShutdown() Return $aResult EndFunc ;==>_NetInfo_NameToIP ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_IPToName ; Description ...: Converts an IP to Internet name ; Syntax.........: _NetInfo_IPToName($ip) ; Return values .: On Success - Returns string containing IP address corresponding to the name ; On Failure - Returns "" and set @error. ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_IPToName($s_Address) Local $objWMIService = ObjGet("winmgmts:\\.\root\cimv2") Local $sQuery = 'SELECT * FROM Win32_PingStatus WHERE address="' & $s_Address & '" AND ResolveAddressNames=True' Local $oColItems = $objWMIService.ExecQuery($sQuery) If IsObj($oColItems) Then Local $sResult For $objItem In $oColItems $sResult = $objItem.ProtocolAddressResolved ExitLoop Next Return $sResult EndIf Return SetError(1, 0, "") EndFunc ;==>_NetInfo_IPToName ; #FUNCTION# ==================================================================================================================== ; Name...........: _NetInfo_GetLocalDNS ; Description ...: Retrive the list of Local DNS in use ; Syntax.........: _NetInfo_GetLocalDNS() ; Return values .: On Success - Returns an array with all Local DNS in use ; $array[0] = DNS1 ; $array[1] = DNS2 ; On Failure - Returns "" and set @error. ; Author ........: Nessie ; =============================================================================================================================== Func _NetInfo_GetLocalDNS() Local $objWMIService = ObjGet("winmgmts:\\.\root\cimv2") Local $sQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE" Local $oColItems = $objWMIService.ExecQuery($sQuery) Local $sIP = @IPAddress1, $aReturn If IsObj($oColItems) Then For $oObjectItem In $oColItems If $oObjectItem.IPAddress(0) == $sIP Then $aReturn = $oObjectItem.DNSServerSearchOrder() EndIf Next If IsArray($aReturn) Then Return $aReturn EndIf EndIf Return SetError(1, 0, "") EndFunc ;==>_NetInfo_GetLocalDNS ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __NetInfo_GetCountryCode ; Description ...: Return the system Country Code in ISO 3166-1 ; Author ........: Nessie ; =============================================================================================================================== Func __NetInfo_GetCountryCode() Local $Ret = DllCall('kernel32.dll', 'ulong', 'GetUserDefaultLCID') If @error Then Return SetError(1, 0, 0) EndIf Local $iLCID = $Ret[0] Local $aRet = DllCall('kernel32.dll', 'int', 'GetLocaleInfoW', 'ulong', $iLCID, 'dword', 0x005A, 'wstr', '', 'int', 2048) If (@error) Or (Not $aRet[0]) Then Return SetError(1, 0, '') EndIf Return $aRet[3] EndFunc ;==>__NetInfo_GetCountryCode ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __NetInfo_GetServerList ; Description ...: Return the list of all avaiable server ; Author ........: Nessie ; =============================================================================================================================== Func __NetInfo_GetServerList($s_CountryCode) Local $sRet Local $bRead = InetRead("http://speedtest.net/speedtest-servers.php", 1) If @error Then Return SetError(1, 0, "") Local $sRead = BinaryToString($bRead) If @error Then Return SetError(1, 0, "") Local $sPattern = 'url="(.*?)upload.php".*cc="' & $s_CountryCode & '"' Local $aRegex = StringRegExp($sRead, $sPattern, 3) If @error Then $sRet = "http://sto-bvrt-01.sys.comcast.net/speedtest/" Else Local $iID = Int(Random(0, UBound($aRegex) - 1)) $sRet = $aRegex[$iID] EndIf Return $sRet EndFunc ;==>__NetInfo_GetServerList ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __NetInfo_RandomText ; Description ...: Used internally within this file, not for general use ; Syntax.........: __NetInfo_RandomText() ; Author ........: Nessie ; =============================================================================================================================== Func __NetInfo_RandomText() Local $sData = '', $sRandom = '' For $i = 1 To 499999 $sRandom = Random(97, 122, 1) $sData &= Chr($sRandom) Next Return $sData EndFunc ;==>__NetInfo_RandomText ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __NetInfo_HTTP_Post ; Description ...: Used internally within this file, not for general use ; Syntax.........: __NetInfo_HTTP_Post($s_Url, $s_Data) ; Author ........: Nessie ; =============================================================================================================================== Func __NetInfo_HTTP_Post($s_Url, $s_Data) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") If @error Then Return SetError(1, 0, "") $oHTTP.Open("POST", $s_Url, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/4.0 (compatible;)") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send($s_Data) Local $oReceived = $oHTTP.ResponseText If $oReceived = "" Then Return SetError(1, 0, "") Return $oReceived EndFunc ;==>__NetInfo_HTTP_Post ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __NetInfo_HTTP_Get ; Description ...: Used internally within this file, not for general use ; Syntax.........: __NetInfo_HTTP_Get($s_Url, $s_Data) ; Author ........: Nessie ; =============================================================================================================================== Func __NetInfo_HTTP_Get($s_Url, $s_Data) Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") If @error Then Return SetError(1, 0, "") $oHTTP.Open("GET", $s_Url, False) $oHTTP.SetRequestHeader("User-Agent", "Mozilla/4.0 (compatible;)") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send($s_Data) Local $oReceived = $oHTTP.ResponseText If $oReceived = "" Then Return SetError(1, 0, "") Return $oReceived EndFunc ;==>__NetInfo_HTTP_GetHi! Previous download: 15 NetInfo v.1.1.0.rar
- 5 replies
-
- netinfo
- download speed
-
(and 4 more)
Tagged with: