What's the fastest way to figure out if the computer your application is running on is connected to the internet? Also, what's the easiest way to download a file ? Thanks.
Printable View
What's the fastest way to figure out if the computer your application is running on is connected to the internet? Also, what's the easiest way to download a file ? Thanks.
I could have sworn someone said VB 2005 had an event that would fire if an internet connection changed state (like got disconnected or connected) but I can't find any information on it. Maybe I was just going crazy?Quote:
Originally Posted by Nove
Anyway, there isn't an easy way to do this. You could attempt to ping a computer or website, but many corporate environments and web servers will block pings so it won't be accurate. Same with attempting to access a specific website via HTTP or HTTPS as websites are not guarenteed to be there and many corporate environments block certain websites or HTTP entirely (or HTTPS).
I have yet to see an accurate way to always tell when you are connected or not, You could check the current IP address and parse it to see what kind of network it's on but there could be internet problems so that also wouldn't be accurate.
Using a WebClient.Quote:
Originally Posted by Nove
You aren't going crazy kas. The My.Computer.Network.IsAvailable property will tell you at any time whether you have an available network connection and the NetworkAvailabilityChanged application event is raised whenever that state changes. Note that this is network availability. If you are connected to a wired or wireless network that is not itself connected to the Internet this will still indicate that the network is available. Also, I'm not sure whether a dialup modem connected to the Internet qualifies as a network connection or not.
Yay, I'm sane!Quote:
Originally Posted by jmcilhinney
Though, parsing your IP would tell you the samething.
There are just too many factors in trying to determine if your computer is online or not so it may just not be possible.
I would imagine it would as that is still a network connection and you're still getting an IP address, it's just another means to get it.Quote:
Originally Posted by jmcilhinney
Though I have no way to test that theory.