Feb 6, 2013

How to ping with unplugged network cable?

Sample scenario:
You've rebooted a router and you want to know when the network connectivity is restored.

Typical PING -t  will not work (test-connection might, but I have not play with it a whole lot)

C:\Users\bob>ping -t www.google.com
Ping request could not find host www.google.com. Please check the name and try again.

So... we do a simple alternative by wrapping ping into a loop:

C:\Users\bob>powershell
PS C:\Users\bob> for (1..1000){ping www.google.com;start-sleep 10}
Ping request could not find host www.google.com. Please check the name and try again.
Ping request could not find host www.google.com. Please check the name and try again.
Ping request could not find host www.google.com. Please check the name and try again.
Ping request could not find host www.google.com. Please check the name and try again.
Pinging www.google.com [74.125.129.99] with 32 bytes of data:
Reply from 74.125.129.99: bytes=32 time=20ms TTL=48
Reply from 74.125.129.99: bytes=32 time=20ms TTL=48
etc..


Now, if you want to get fancy, you can use while loop and add ($?) or (!$?) and pair it up with Send-MailMessage or other fanciness of your choice.

GG