Groups > Microsoft > Windows PowerShell > Re: Is network available?




Is network available?

Is network available?
Tue, 15 Apr 2008 04:21:22 -070
Hello all.

Is it best way to check that network available?

if([Net.NetworkInformation.NetworkInterface]::GetIsNetworkAvailable())
{
(New-Object Net.NetworkInformation.Ping).Send('google.com').Status}

Post Reply
Re: Is network available?
Tue, 15 Apr 2008 06:01:25 -070
Can I say that .NET does not provide a simple and reliable method for
Post Reply
Re: Is network available?
Tue, 15 Apr 2008 08:33:59 -040
ajax76 wrote:
> Is it best way to check that network available?
> 
> if([Net.NetworkInformation.NetworkInterface]::GetIsNetworkAvailable())

Just based on what I see from calling the GetAllNetworkInterfaces() static 
method on the same class and doing some quick tests, I would say this is not a 
foolproof test.  According to MSDN:

"A network connection is considered to be available if any network
interface is 
marked "up" and is not a loopback or tunnel interface."

One of the two VPN tunnel drivers I'm using don't seem to mark itself as such, 
or the above is not otherwise reliable because when I unhooked my NIC cable just

now (no wifi link either), GetIsNetworkAvailable() was still true.

> (New-Object Net.NetworkInformation.Ping).Send('google.com').Status}

Otherwise, I'd say a ping to the Internet is always good if that's the criteria

you care about.  I usually go the WMI route and look at 
win32_networkadapterconfiguration, but your way seems to work just fine.

-- 

Hal Rottenberg
Blog: http://halr9000.com
Webmaster, Psi (http://psi-im.org)
Post Reply
about | contact