Jump to content

Net Speed upload download


 Share

Recommended Posts

I am trying to display net speeds from a website (scanmyspeed.com) and then display it.  It opens up IE (which later I will set to hidden) and clicks start but I can't get the values to display in the GUI.  My goal was to get the results once it was completed but I'm also stumped on how to figure out when its complete and then display. Here is a quick GUI to display them but I'm not having any luck.

#include<IE.au3>
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
$NetSpeedGUI = GUICreate("Net Speed", 323, 72)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
GUICtrlCreateGroup("Download Speed", 8, 0, 153, 65)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$dmbps = GUICtrlCreateLabel("", 16, 24, 93, 33)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Mbps", 112, 32, 43, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Upload Speed", 168, 0, 145, 65)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$umbps = GUICtrlCreateLabel("", 176, 24, 93, 33)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Mbps", 267, 31, 43, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
$oIE = _IECreate("http://www.scanmyspeed.com/", 0, 1, 1)
$oBegin = _IEGetObjById($oIE, "scanstart")
_IEAction($oBegin, "click")

While 1
    $oDown = _IEGetObjById($oIE, "scandmbit")
    GUICtrlSetData($dmbps, $oDown)
    $oWait = _IEGetObjById($oIE, "scanumbit")
    GUICtrlSetData($umbps, $oWait)
    Sleep(500)
WEnd
Func CLOSE()
_IEQuit($oIE)
    Exit
EndFunc

 

Link to comment
Share on other sites

#include<IE.au3>
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
$NetSpeedGUI = GUICreate("Net Speed", 323, 72)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
GUICtrlCreateGroup("Download Speed", 8, 0, 153, 65)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$dmbps = GUICtrlCreateLabel("", 16, 24, 93, 33)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Mbps", 112, 32, 43, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Upload Speed", 168, 0, 145, 65)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$umbps = GUICtrlCreateLabel("", 176, 24, 93, 33)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Mbps", 267, 31, 43, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
$oIE = _IECreate("http://www.scanmyspeed.com/", 0, 1, 1)
$oBegin = _IEGetObjById($oIE, "scanstart")
_IEAction($oBegin, "click")

While 1
$oDown = _IEGetObjById($oIE, "scandmbit")
$sDown = _IEPropertyGet($oDown, "innerText")
GUICtrlSetData($dmbps, $sDown)
$oWait = _IEGetObjById($oIE, "scanumbit")
$sWait = _IEPropertyGet($oWait, "innerText")
GUICtrlSetData($umbps, $sWait)
Sleep(500)
WEnd


Func CLOSE()

_IEQuit($oIE)

Exit

EndFunc
Link to comment
Share on other sites

  • 4 months later...

Bringing back an old post of mine to improve on what I have.  With the code above I can get the speeds but I have no idea on the time it takes to finish the test.  So currently I have a sleep of 30 seconds to allow time to finish.

Doing more research and testing I wanted a more accurate test and found this website: http://testmy.net/

I want to check and display the results while updating the status of the test, while testing, in another GUI, while hiding IE.  I'm having issues reading from IE.  I've tried several of the IE options but still get nowhere because the source changes rapidly and doesn't have ID's just classes. Right about now (after 3 hours and still nowhere) I would take any advice.

Pretty much using the website to generate the information and displaying only numbers or even using the detailed results page to generate a log.

I haven't came up with any code yet to accomplish this and I'm not asking anyone to write a finished product just need to be leaned in the right direction.

Oh I do have this lol...

$oIE = _IECreate("http://testmy.net/", 0, 1)
$oBegin = _IEGetObjById($oIE, "link")
_IEAction($oBegin, "click")
Edited by Rogue5099
Link to comment
Share on other sites

 

Bringing back an old post of mine to improve on what I have.  With the code above I can get the speeds but I have no idea on the time it takes to finish the test.  So currently I have a sleep of 30 seconds to allow time to finish.

Doing more research and testing I wanted a more accurate test and found this website: http://testmy.net/

I want to check and display the results while updating the status of the test, while testing, in another GUI, while hiding IE.  I'm having issues reading from IE.  I've tried several of the IE options but still get nowhere because the source changes rapidly and doesn't have ID's just classes. Right about now (after 3 hours and still nowhere) I would take any advice.

Pretty much using the website to generate the information and displaying only numbers or even using the detailed results page to generate a log.

I haven't came up with any code yet to accomplish this and I'm not asking anyone to write a finished product just need to be leaned in the right direction.

Oh I do have this lol...

$oIE = _IECreate("http://testmy.net/", 0, 1)
$oBegin = _IEGetObjById($oIE, "link")
_IEAction($oBegin, "click")

It isn't more accurate. It isn't a flash test. And i am not sure about it.

You want to display the progress while the pages are loading? You can loop the url and everytime it changes you can set a data to your inputs. To get the url use _IEPropertyGet($oIE, "locationurl")

However when the test finishes the ie fires a complete state which means that _IELoadWait will return but the content wont be displayed as fast as the reade state of the IE.

So you will have to add Sleep()

If you want a better work check the WinHttp.au3 and try it with the http functions. A lot faster and better since you want to do in in invisible mode of the IE

Edit: to get controls of inputs etc use _IETagNameGetCollection()

 

Edited by AutID
Link to comment
Share on other sites

Searching google i made this little snipet for you.

#include <GUIConstantsEx.au3>
Global $__gServer = ""
Opt("GUIOnEventMode", 1)
$NetSpeedGUI = GUICreate("Net Speed", 323, 72)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
GUICtrlCreateGroup("Download Speed", 8, 0, 153, 65)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$dmbps = GUICtrlCreateLabel("", 16, 24, 93, 33)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Mb/s", 112, 32, 43, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Upload Speed", 168, 0, 145, 65)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$umbps = GUICtrlCreateLabel("", 176, 24, 93, 33)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Mb/s", 267, 31, 43, 24)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
Local $Download_Speed = _NetInfo_GetDownloadSpeed()
$Download_Speed = $Download_Speed[0] / 1000
Local $Upload_Speed = _NetInfo_GetUploadSpeed()
If $Upload_Speed < 1000 Then
 $Upload_Speed = 0 & "." & $Upload_Speed
Else
 $Upload_Speed = StringTrimRight($Upload_Speed, 3) & "." & StringTrimLeft($Upload_Speed, 1)
EndIf
GUICtrlSetData($dmbps, $Download_Speed)
GUICtrlSetData($umbps, $Upload_Speed)
While 1
 Sleep(250)
WEnd
Func CLOSE()
 Exit
EndFunc
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
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
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
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) / 4999)
 Return $iRet
EndFunc   ;==>_NetInfo_GetUploadSpeed
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
Func __NetInfo_RandomText()
 Local $sData = '', $sRandom = ''
 For $i = 1 To 499999
  $sRandom = Random(97, 122, 1)
  $sData &= Chr($sRandom)
 Next
 Return $sData
EndFunc
Found the UDF in the example scripts.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...