I am trying to ping all the systems available in the local area network using terminal command.
Can any one tell me how to do this?
4 Answers
You can install an application called nmap.
sudo apt-get install nmap Then you can check your entire network for all connected IP addresses by typing in the following:
nmap -sP 192.168.1.1/24 The above command will scan all IP addresses starting at 192.168.1.1 through 192.168.1.254 and show you all IPs that responded.
You can scan other IP address ranges like 192.168.0.1 - 192.168.1.254 by typing in the following:
nmap -sP 192.168.0.1/23 A typical scan might return something like the following:
terrance@terrance-ubuntu:~$ nmap -sP 10.0.0.1/24 Starting Nmap 6.40 ( ) at 2015-12-24 00:20 MST Nmap scan report for Linksys03773 (10.0.0.1) Host is up (0.00078s latency). Nmap scan report for terrance-ubuntu (10.0.0.100) Host is up (0.00020s latency). Nmap scan report for android (10.0.0.148) Host is up (0.099s latency). Nmap scan report for PC (10.0.0.149) Host is up (0.0014s latency). Nmap scan report for 10.0.0.150 Host is up (0.0016s latency). Nmap scan report for 10.0.0.165 Host is up (0.011s latency). Nmap scan report for 10.0.0.169 Host is up (0.010s latency). Nmap scan report for 10.0.0.179 Host is up (0.014s latency). Nmap scan report for android (10.0.0.181) Host is up (0.093s latency). Nmap scan report for android (10.0.0.188) Host is up (0.043s latency). Nmap scan report for android (10.0.0.196) Host is up (0.014s latency). Nmap scan report for 10.0.0.253 Host is up (0.0013s latency). Nmap done: 256 IP addresses (12 hosts up) scanned in 4.46 seconds I hope this helps!
fping is another command to ping all ip in LAN.
fping -a -r 0 -g 192.168.9.0/24 192.168.9.48 192.168.9.71 192.168.9.72 192.168.9.73 192.168.9.75 192.168.9.79 192.168.9.81 192.168.9.82 ICMP Redirect from 192.168.9.4 for ICMP Echo sent to 192.168.9.83 192.168.9.84 192.168.9.85 192.168.9.87 192.168.9.88 192.168.9.90 192.168.9.92 192.168.9.104 192.168.9.106 192.168.9.108 192.168.9.109 192.168.9.116 192.168.9.117 ICMP Host Unreachable from 192.168.9.214 for ICMP Echo sent to 192.168.9.1 192.168.9.120 ICMP Host Unreachable from 192.168.9.214 for ICMP Echo sent to 192.168.9.2 -a Show systems that are alive.
-r n Retry limit (default 3). This is the number of times an attempt at pinging a target will be made, not including the first try.
-g addr/mask Generate a target list from a supplied IP netmask, or a starting and ending IP. Specify the netmask or start/end in the targets portion of the command line. If a network with netmask is given, the network and broadcast addresses will be excluded.
To scan range of IP addresses from 192.168.0.1 to 192.168.0.9 just run:
sudo fping -s -g 192.168.0.1 192.168.0.9 -r 1 That will output:
192.168.0.1 is alive 192.168.0.7 is alive 192.168.0.2 is unreachable 192.168.0.3 is unreachable 192.168.0.4 is unreachable 192.168.0.5 is unreachable 192.168.0.6 is unreachable 192.168.0.8 is unreachable 192.168.0.9 is unreachable 9 targets 2 alive 7 unreachable 0 unknown addresses 14 timeouts (waiting for response) 16 ICMP Echos sent 2 ICMP Echo Replies received 0 other ICMP received 0.05 ms (min round trip time) 0.44 ms (avg round trip time) 0.84 ms (max round trip time) 2.183 sec (elapsed real time) Here is the ubuntu manual to use fping with different options.
There are 2 ways:
- Use
nmapto scan entire local subnets in only one command. For example:nmap -sP 192.168.0.1/24 - Use
arp-scan, it sends ARP packets to hosts on the local network and displays any responses that are received. By default, it's not installed. So install it by the commandsudo apt-get install arp-scan.
Once it's accomplished. Launch this command to scan entire local network on the specified interface (For example, your network interface is named eth0):
sudo arp-scan --interface=eth0 --localnet or give a specific subnet:
sudo arp-scan --interface=eth0 192.168.0.1/24 The simplest way to ping all the hosts on a LAN is with IPv6:
ping6 -nc2 ff02::1%eth0 The -n flag means no reverse DNS will be performed. Without that it would be slowed down by trying to perform reverse DNS on link-local addresses, which is not going to work anyway.
The -c2 flag means it will send only two pings before terminating.
The address ff02::1 is an anycast address targeting all hosts on the link.
Finally %eth0 is the notation appended to link-local IPv6 addresses in order to indicate which interface to be using. Usually this will be eth0 or wlan0.
You can do the same with IPv4, but it involves an additional step to look up the broadcast address for the segment.
$ ifconfig eth0 eth0 Link encap:Ethernet HWaddr b8:ae:ed:a4:08:97 inet addr:172.20.124.289 Bcast:172.20.124.255 Mask:255.255.255.0 inet6 addr: fe80::baae:edff:fea4:897/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:92446832 errors:0 dropped:669 overruns:0 frame:0 TX packets:52031936 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:97720895471 (97.7 GB) TX bytes:18694928767 (18.6 GB) $ ping -bnc2 172.20.124.255 Here I first used ifconfig to see what the IP address of eth0 is and then I ping it. Additionally I need the -b flag to tell ping that I really do want to ping a broadcast address.