Some you need to know which IP in a specific range is already in use. With Windows PowerShell there is a simple way to ping a IP range.
You can use the .Net class System.Net.Networkinformation.Ping to do this.
$ping = New-Object System.Net.Networkinformation.Ping 1..254 | % { $ping.send(“192.168.100.$_”) | select address, status }
You can also have a look at the new Test-Connection or Test-NetConnection PowerShell cmdlets.
Tags: IP range, Microsoft, Ping, PowerShell, Windows Last modified: August 18, 2018
First, if you want a bit more detail or more control over the ping, you could use the Test-Connection cmdlet. If you want a simple up/down you could use something like this:
1..254 | foreach { new-object psobject -prop @{Address=”172.16.10.$_”;Pin
g=(test-connection “172.16.10.$_” -quiet -count 1)}}
I’m only sending a single ping in this example.
The other problem with the ping class is that if the destination is unreachable, the address you get back is yours., I don’t think that is what you intended.
I took this and ran with it.
Ping IP Range with Windows #PowerShell http://bit.ly/sCjeCR
thanks. it was very usefull
It is possible to filter unreachable hosts and shows only “success” hosts?
I know I’m a bit late to the party, but I thought I’d add that when I run the commands, only xxx.xxx.xxx.1 is pinged…
But if I run “1..254 | % { write-host $_ }” then it gives me the number 1 to 254, each on a separate line…
Hah, I figured it out, of course it only returns my machines own address until it finds an address that actually return a ping -_-
Hi Thomas,
I created a ping ip range script using PowerShell workflows :-)
Check my github: https://github.com/stefanstranger/PowerShell/commit/61e676459e7eed70e811aafd3e03b83c37668821
/Stefan
Nice! :)
Hi all , i need to query specific segments and get the segment and description from sites and services
199.52.213.0/24
199.52.241.128/26
199.49.54.0/23 (Segment not created)
199.49.63.0/26 (Segment not created)
199.49.65.0/26 (Segment not created)
199.49.65.64/26 (Segment not created)
199.49.70.0/26 (Segment not created)
and os on
is there a powerhsle to export all IP Segments to CSV file ?
I know it’s old but if someone stumbles upon this and has the same question as Mahmood:
Change the second line to this:
1..254 | % { $ping.send(“192.168.1.$_”) | where {$_.status -eq “Success”} | select address, status }
Hi. I get this output, (address column truncated).
Any easy way to fix that?
Address Status
150…. Success
Timedout
150…. Success
1..254 | foreach { new-object psobject -prop @{Address=”172.16.10.$_”;Pin
g=(test-connection “172.16.10.$_” -quiet -count 1)} | Format-Table -autosize}
This may work, but has horrible readability. I would never use a command like this in my code. I would prefer Stefan Strangers solution.
Thank for putting this up there, nice quick method to test a load of IPs :)
thanks :)