So, yesterday I needed to find a WIFI printer that was attached to the network, but whose IP address I did not have. I realize I could have opened the Apple Airport Utility to see what WIFI IPs were in use. But, this utility does not show the IPs attached via Ethernet, and it’s only useful if you are running an Apple Extreme or Apple Express access point. I guess I was being stubborn, and just wanted an old fashioned command line way of doing a ping sweep. After a bit of trial and error, here is the command for OS X:
- Open a Terminal Window
- Run the command: for i in {150..169}; do ping -c 2 192.168.2.$i | grep ‘bytes’ ; done
- Looking at the screen shot, three IPs responded to my inquiry
Now, there are several things of note regarding this command. I limited the command to sweep across IPs that are in my DHCP range. If I had wanted to sweep the entire subnet, then I should have used {1..254} instead of {150..169} in my command. Also, I wanted the count of responses to be two. If you want to emulate a typical DOS ping, you might want to replace -c 2 with -c 4 in order to get four responses per IP. You will want to use the subnet of your network instead of using 192.168.2.$i, which you can find by running ifconfig | grep inet to determine your current IP address. The command is limiting the output to the lines with the word ‘bytes’ in them, this was intended to reduce clutter in the output. Finally, you need to remember to include the semi column and “done” in the line, this is not a typo. If you forget, you will find yourself staring at a prompt without an output and need to use the control-C keystrokes to get back to the command line in order to retry your command.