A collection of computer systems and programming tips that you may find useful.
 
Brought to you by Craic Computing LLC, a bioinformatics consulting company.

Monday, February 10, 2014

Using Ping to find machines on your network

The UNIX command ping is used to test if specific machines are active on a network

$ ping 10.0.1.9
PING 10.0.1.9 (10.0.1.9): 56 data bytes
64 bytes from 10.0.1.9: icmp_seq=0 ttl=255 time=0.619 ms
[...]

I have been using ping for years but last week I found out that you can ping the broadcast address of a network (x.x.x.255) and see all the machines on that network that are configured to respond to ping:

$ ping 10.0.1.255
PING 10.0.1.255 (10.0.1.255): 56 data bytes
64 bytes from 10.0.1.10: icmp_seq=0 ttl=64 time=0.071 ms
64 bytes from 10.0.1.9: icmp_seq=0 ttl=255 time=0.534 ms
64 bytes from 10.0.1.1: icmp_seq=0 ttl=255 time=0.544 ms
[...]

Really useful if you need the IP address for a machine that used DHCP to assign its address

A complementary command is arp -a 

This displays information of all the network interfaces for a machine and reports the interface, the IP address and the MAC address of each entry in the address resolution tables.

$ arp -a
? (10.0.1.1) at b8:8d:12:5a:ad:77 on en0 ifscope [ethernet]
? (10.0.1.2) at b8:8d:12:5a:ad:77 on en0 ifscope [ethernet]
? (10.0.1.6) at 70:56:81:ad:b6:d1 on en0 ifscope [ethernet]
? (10.0.1.7) at b8:8d:12:5a:ad:77 on en0 ifscope [ethernet]
? (10.0.1.9) at 70:56:81:c5:fb:2d on en0 ifscope [ethernet]
[...]

Note that these addresses are not necessarily active. You can see link reachability information using arp -al