![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | What's in a Ping? or a Ping by another method. Hi, I have been wondering about this for a while. Many of the scripts here use this method to Ping a server: $ping = new-object System.Net.NetworkInformation.Ping $reply = $ping.Send($srv) if ($reply.status -eq "Success") { do something } Else { Write-Host $srv " Does Not Ping" } However, I have been using this method with good results: $response = Get-WmiObject -query "Select * From Win32_PingStatus Where Address = '$srv'" if( ($response -eq $null) -or ($response.StatusCode -ne 0)) { Write-Host $srv " Does Not Ping" } Else { do something } So, What's the difference? or what is the advantage of one over the other? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: What's in a Ping? or a Ping by another method. no major different... one is .NET the other is WMI. One thing the WMI can offer is a remote ping. Brandon Shell [MVP] ------------------------ Blog: http://www.bsonposh.com/ Author: http://www.TurboChargeAD.org Profile: https://mvp.support.microsoft.com/profile/Brandon O> Hi, O> O> I have been wondering about this for a while. O> O> Many of the scripts here use this method to Ping a server: O> O> $ping = new-object System.Net.NetworkInformation.Ping O> $reply = $ping.Send($srv) O> if ($reply.status -eq "Success") O> { do something } Else { Write-Host $srv " Does Not Ping" } O> However, I have been using this method with good results: O> O> $response = Get-WmiObject -query "Select * From Win32_PingStatus O> Where Address = '$srv'" O> O> if( ($response -eq $null) -or ($response.StatusCode -ne 0)) { O> Write-Host $srv " Does Not Ping" } Else { do something } O> O> So, What's the difference? or what is the advantage of one over the O> other? O> |
My System Specs![]() |
| | #3 (permalink) |
| | RE: What's in a Ping? or a Ping by another method. A ping is an ICMP echo request. Both of these methods send one, so there is very little difference from a networking perspective. "OldDog" wrote: Quote: > Hi, > > I have been wondering about this for a while. > > Many of the scripts here use this method to Ping a server: > > $ping = new-object System.Net.NetworkInformation.Ping > $reply = $ping.Send($srv) > if ($reply.status -eq "Success") > { do something } Else { Write-Host $srv " Does Not Ping" } > > > However, I have been using this method with good results: > > $response = Get-WmiObject -query "Select * From Win32_PingStatus Where > Address = '$srv'" > > if( ($response -eq $null) -or ($response.StatusCode -ne 0)) > { Write-Host $srv " Does Not Ping" } Else { do something } > > > So, What's the difference? or what is the advantage of one over the > other? > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: What's in a Ping? or a Ping by another method. On Feb 18, 3:10*pm, Brandon Shell [MVP] <a_bshell.m...@xxxxxx> wrote: Quote: > no major different... one is .NET the other is WMI. > > One thing the WMI can offer is a remote ping. > > Brandon Shell [MVP] > ------------------------ > Blog:http://www.bsonposh.com/ > Author:http://www.TurboChargeAD.org > Profile:https://mvp.support.microsoft.com/profile/Brandon > > O> Hi, > O> > O> I have been wondering about this for a while. > O> > O> Many of the scripts here use this method to Ping a server: > O> > O> $ping = new-object System.Net.NetworkInformation.Ping > O> $reply = $ping.Send($srv) > O> if ($reply.status -eq "Success") > O> { do something } Else { Write-Host $srv " Does Not Ping" } > O> However, I have been using this method with good results: > O> > O> $response = Get-WmiObject -query "Select * From Win32_PingStatus > O> Where Address = '$srv'" > O> > O> if( ($response -eq $null) -or ($response.StatusCode -ne 0)) { > O> Write-Host $srv " Does Not Ping" } Else { do something } > O> > O> So, What's the difference? or what is the advantage of one over the > O> other? > O> prefered over the WMI on this forum? BTW I get odd errors when I use the .NET method if the machine I am trying to ping does not exist. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: What's in a Ping? or a Ping by another method. shrug... I prefer the WMI one ![]() Brandon Shell [MVP] ------------------------ Blog: http://www.bsonposh.com/ Author: http://www.TurboChargeAD.org Profile: https://mvp.support.microsoft.com/profile/Brandon O> On Feb 18, 3:10 pm, Brandon Shell [MVP] <a_bshell.m...@xxxxxx> O> wrote: O> Quote: Quote: >> no major different... one is .NET the other is WMI. >> >> One thing the WMI can offer is a remote ping. >> >> Brandon Shell [MVP] >> ------------------------ >> Blog:http://www.bsonposh.com/ >> Author:http://www.TurboChargeAD.org >> Profile:https://mvp.support.microsoft.com/profile/Brandon >> O> Hi, >> O> >> O> I have been wondering about this for a while. >> O> >> O> Many of the scripts here use this method to Ping a server: >> O> >> O> $ping = new-object System.Net.NetworkInformation.Ping >> O> $reply = $ping.Send($srv) >> O> if ($reply.status -eq "Success") >> O> { do something } Else { Write-Host $srv " Does Not Ping" } >> O> However, I have been using this method with good results: >> O> >> O> $response = Get-WmiObject -query "Select * From Win32_PingStatus >> O> Where Address = '$srv'" >> O> >> O> if( ($response -eq $null) -or ($response.StatusCode -ne 0)) { >> O> Write-Host $srv " Does Not Ping" } Else { do something } >> O> >> O> So, What's the difference? or what is the advantage of one over >> the >> O> other? >> O> O> prefered over the WMI on this forum? O> O> BTW I get odd errors when I use the .NET method if the machine I am O> trying to ping does not exist. O> |
My System Specs![]() |
| | #6 (permalink) |
| | RE: What's in a Ping? or a Ping by another method. One big difference is execution time. Using the .net method I can ping-sweep an entire class c network on our internal network and do a dns resolution on anything that answers in about 2 minutes. I started off trying this with WMI, and got tired of waiting for it to finish. "OldDog" wrote: Quote: > Hi, > > I have been wondering about this for a while. > > Many of the scripts here use this method to Ping a server: > > $ping = new-object System.Net.NetworkInformation.Ping > $reply = $ping.Send($srv) > if ($reply.status -eq "Success") > { do something } Else { Write-Host $srv " Does Not Ping" } > > > However, I have been using this method with good results: > > $response = Get-WmiObject -query "Select * From Win32_PingStatus Where > Address = '$srv'" > > if( ($response -eq $null) -or ($response.StatusCode -ne 0)) > { Write-Host $srv " Does Not Ping" } Else { do something } > > > So, What's the difference? or what is the advantage of one over the > other? > |
My System Specs![]() |
| | #7 (permalink) |
| | RE: What's in a Ping? or a Ping by another method. My experience has been quite different and actually along those lines you can specify the time out with WMI. I do not believe you can do that with the .NET provider. Brandon Shell [MVP] ------------------------ Blog: http://www.bsonposh.com/ Author: http://www.TurboChargeAD.org Profile: https://mvp.support.microsoft.com/profile/Brandon RC> One big difference is execution time. Using the .net method I can RC> ping-sweep an entire class c network on our internal network and do RC> a dns resolution on anything that answers in about 2 minutes. RC> RC> I started off trying this with WMI, and got tired of waiting for it RC> to finish. RC> RC> "OldDog" wrote: RC> Quote: Quote: >> Hi, >> >> I have been wondering about this for a while. >> >> Many of the scripts here use this method to Ping a server: >> >> $ping = new-object System.Net.NetworkInformation.Ping >> $reply = $ping.Send($srv) >> if ($reply.status -eq "Success") >> { do something } Else { Write-Host $srv " Does Not Ping" } >> However, I have been using this method with good results: >> >> $response = Get-WmiObject -query "Select * From Win32_PingStatus >> Where Address = '$srv'" >> >> if( ($response -eq $null) -or ($response.StatusCode -ne 0)) { >> Write-Host $srv " Does Not Ping" } Else { do something } >> >> So, What's the difference? or what is the advantage of one over the >> other? >> |
My System Specs![]() |
| | #8 (permalink) |
| | RE: What's in a Ping? or a Ping by another method. Try this. get-date $network = "10.1.3.0" [int]$timeout = 20 [switch]$resolve = $true [int]$TTL = 128 [switch]$DontFragment = $false [int]$buffersize = 32 $options = new-object system.net.networkinformation.pingoptions $options.TTL = $TTL $options.DontFragment = $DontFragment $buffer=([system.text.encoding]::ASCII).getbytes("a"*$buffersize) foreach ($a in 1..254){ $remotehost = $($network.trim("0")) + $a $ping = new-object system.net.networkinformation.ping $reply = $ping.Send($remotehost,$timeout,$buffer,$options) if ($resolve) { $hostname = ([System.Net.Dns]::GetHostEntry($remotehost)).hostname if ($hostname -eq $remotehost){$hostname = "No RDNS"} } if ($reply.status -eq "Success"){$remotehost + "`t" + $reply.status + "`t`t" + $hostname} else {$remotehost + "`t" + $reply.status + "`t" + $hostname} } get-date "Brandon Shell [MVP]" wrote: Quote: > My experience has been quite different and actually along those lines you > can specify the time out with WMI. I do not believe you can do that with > the .NET provider. > > > Brandon Shell [MVP] > ------------------------ > Blog: http://www.bsonposh.com/ > Author: http://www.TurboChargeAD.org > Profile: https://mvp.support.microsoft.com/profile/Brandon > > RC> One big difference is execution time. Using the .net method I can > RC> ping-sweep an entire class c network on our internal network and do > RC> a dns resolution on anything that answers in about 2 minutes. > RC> > RC> I started off trying this with WMI, and got tired of waiting for it > RC> to finish. > RC> > RC> "OldDog" wrote: > RC> Quote: Quote: > >> Hi, > >> > >> I have been wondering about this for a while. > >> > >> Many of the scripts here use this method to Ping a server: > >> > >> $ping = new-object System.Net.NetworkInformation.Ping > >> $reply = $ping.Send($srv) > >> if ($reply.status -eq "Success") > >> { do something } Else { Write-Host $srv " Does Not Ping" } > >> However, I have been using this method with good results: > >> > >> $response = Get-WmiObject -query "Select * From Win32_PingStatus > >> Where Address = '$srv'" > >> > >> if( ($response -eq $null) -or ($response.StatusCode -ne 0)) { > >> Write-Host $srv " Does Not Ping" } Else { do something } > >> > >> So, What's the difference? or what is the advantage of one over the > >> other? > >> > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Can't ping XP (even IP) but XP can ping Vista x64 | Vista networking & sharing | |||
| I can ping with IPv6. I can not ping with IPv4. | Vista General | |||
| cannot ping through vpn | Vista networking & sharing | |||
| cant ping my self | Vista General | |||
| Can Only Ping One way | Vista networking & sharing | |||