Archive: Detect Internet Connection's Speed?


Detect Internet Connection's Speed?
I've found a precious piece of code by kichik on this forum thread and I use it to detect If target system is connected.
I know that Inetc plugin while downloading shows info about speed, remaining time etc.
What I want is to show some exclusive info about the estimated download time with current connection just before the actual download process is going to start. Since I know a little about APIs, I only guess that it should be possible with system plugin, and I wonder if someone from the community has achieved such a thing.
Thanks


You can get connection type with InternetGetConnectedState http://forums.winamp.com/showthread.php?postid=1494691


Originally posted by Takhir
You can get connection type with InternetGetConnectedState http://forums.winamp.com/showthread.php?postid=1494691
Takhir thanks for the response!
I tried it and it returns an empty string! I don't know why...
I use kichik's function, the one I mentioned above, I have just replaced google with the actual server where I'm going to connect, and this is always successful. When I remove the network cable it detects no connection, when I set the cable back, successfully detects connection, when I block my pc with the firewall it detects no connection, and so on. I tested this function 100 times and always I'm getting true results.
Anyway this is not the point. This has been achieved. As I mentioned, I'd like to show some exclusive info to the end user, so, the point is if there is a function that somehow detects the speed of the connection before Inetc starts downloading, and not if there is connection. :-)

Just to keep you informed :)


System::Call 'wininet.dll::InternetGetConnectedState(*i .r0, i 0) i.r1'
MessageBox MB_OK "$1 $0 Modem=1, LAN=2, Proxy=4, RAS=0x10, Offline=0x20 Configured=0x40"
shows 18 - LAN and INTERNET_RAS_INSTALLED.
The only way to test performance is to download a file (silent). GetTickCount() returnes ms. Bigger file - higher precision, but more time for customer to press all buttons ;)

Great!
The code that you've posted above works as it expected!
In the envirenment that I'm currently running, it returns "1 18". I guess is means Modem and LAN and INTERNET_RAS_INSTALLED.
Perhaps you know what it returns when detects a single dial up modem?
I'm asking this because I'm thinking that probably these info are enough. When a dial up modem is detected, I could inform users that depending on modem speed, the download would need aprox. <time>, when a Lan/dsl is detected, then there is not need for extra info, they will see the actual download speed from Inetc.
Thanks in advance!


No, function returns $1 and 1 means "state is connected" (MSDN). 18 is 0x12 that means presisely LAN + RAS. You should use 'and' to get modem bit: IntOp $0 $0 & 1


Takhir thanks a lot!
Now I think I got it :-) I had to make various tests by enable/disable proxy, plug/unplug, etc, and use IntFmt to get it :-)
Now what I have is the following, please could you confirm that I'm in the right direction?

System::Call 'wininet.dll::InternetGetConnectedState(*i .r0, i 0) i.r1'
Detailprint '$$1==$1 (connected state)'
; When plugged at this point $1 = 1
; When plugged+proxy at this point $1 = 1
; When unplugged at this point $1 = 0

Detailprint '$$0==$0 (connection)'
; When plugged at this point $0 = 18
; When plugged+proxy at this point $0 = 86
; When unplugged at this point $0 = 16

IntFmt $R1 "0x%X" "$0"
Detailprint '$$R1==$R1 (connection in hex)'
; When plugged at this point $R1 = 0x12
; When plugged+proxy at this point $R1 = 0x56
; When unplugged at this point $R1 = 0x10

IntOp $R0 $0 & 1
Detailprint '$$R0==$R0 (modem bit)'
; When plugged at this point $R0 = 0
; When plugged+proxy at this point $R0 = 0
; When unplugged at this point $R0 = 0

Thanks in advance!

Well, I was running the above code several times and I think this is all what I need.
With this code, I'm able to achieve my plan in a very single step.
Checking var $1 would tell me that the target is connected, in combination with var $R0, I would capture if the connection is lan or a dial up modem.
I guess the only thing I need further confirm is to find a pc with modem installed and check the accuracy of the code in that environment.


Well, the code works accurately on both environments LAN/Dial up modem :-)
Thank you very much Takhir!

С НОВЫМ ГОДОМ


Thanks Major Dude ;)
eftikhes to neon ethos (may be a bit early, Greece and Russia selebrate both January 1 and 14 :) )
The only remaining question is default connection and how to use the fast one from Inetc ...


Yes... a newbie Major Dude :-)

eftikhes to neon ethos (may be a bit early, Greece and Russia selebrate both January 1 and 14)
This isn't so bad :-) It is only that we need 2 bottles of vodka when we're going to celebrate twice :-)


The only remaining question is default connection and how to use the fast one from Inetc ...
I really stuck on this, I can't figure it out.
Though, I have to assume that a normal user who has both connections, would never use as default connection the dial up, normally, would use as default the fast one, leaving the dial up just for cases when the fast connection is disabled.

Though, I have to assume that a normal user who has both connections, would never use as default connection the dial up, normally, would use as default the fast one, leaving the dial up just for cases when the fast connection is disabled.
This case might be better to check LAN bit in the code function returned ;) It gives you fastest interface. You can supose it is default. And to check modem bit otherwise.

This case might be better to check LAN bit in the code function returned It gives you fastest interface. You can suppose it is default. And to check modem bit otherwise.
Obviously this is the right way to go, hopefully I wouldn't meet the weird case when a dial up connection is defined as default/always dial. (Case Internet properties/connections "always dial my default connection" radiobutton is checked.)
In both other cases "never dial a connection" radiobutton or "dial whenever a network connection is not present" radiobutton, the LAN bit is detected.