perl -MIO -le 'sleep 10 until IO::Socket::INET->new("www.google.com:80
+"); print "Action!"'
| [reply] [d/l] |
ActiveState Perl has Win32-IPConfig and Win32-IPHelper available via PPM. They will be able to tell you if your interface is up, whether you have a DHCP lease, whether there is a gateway on that interface (so you can guess that that's your internet connection.)
You'll still need to verify that you can connect through the network connection you find, but this will be a good start. I would suggest either pinging your dns server or making an http header request to a web server that you think is reliable, or possibly the web server you want to work against.
I say ping your dns server, because if you can't resolve names to addresses, you might not get very far anyway. Unless you're running a caching nameserver locally on your network or in your router.
Many networks are blocking ICMP packets from ping these days, as well as traceroute packets, so that's why I suggest the http request. Do the net a favor and just do the HEAD request instead of grabbing the entire page.
This should be enough to get you started. Good luck. | [reply] |
Thanks for pointing me in the right direction.
| [reply] |
that is platform dependent.
for windows you will need to check a registry key (not sure which, but i can find out if you want). | [reply] |
Sorry, should have said I am using windowz. That would be great, thanks. So the reg entry actualy tells you if the connection is live, interesting.
| [reply] |
after rereading the thing i found that the registry-key is only true for dialup-connections.
afaik, there is no way to detect wether the computer is connected via LAN.
| [reply] |