Linux : Ping all the host in the subnet
Is there anything similar to this one in linux ? My intention is to find one mac address as below after pinging all the hosts:
3 Answers 3
All you are doing is pinging the broadcast address. The GNU/Linux version of ping requires that you use the -b switch
-b Allow pinging a broadcast address
There doesn’t appear to be a direct equivalent of the Solaris -s switch either (it’s only pinging every second and gathering stats) but perhaps it’s buried in the Linux man pages- well worth a read (as may be the Solais ones ).
I wouldn’t go pinging 255.255.255.255 either (it may take a while to complete) I’d use the broadcast address of the network I was connected to.
You can always try to ping to the broadcast address of your subnet. It depends on your local network setup, but you can find it out with
$ ifconfig wlp4s0 | grep Bcast inet addr:192.168.199.47 Bcast:192.168.199.255 Mask:255.255.255.0
Pinging from Linux requires the -b commandline switch, which is kind of a precaution of the command.
However, this does not guarantee that you will collect all MAC addresses from all devices connected to your subnet as it is up the the very device to actually answer ICMP ECHO requests sent to broadcast addresses, even if that was intended otherwise in the early ages of the TCP/IP RFCs (see whether /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts is set to 1).
To be more sure to cover all addresses, ping them individually with
$ for ip in 192.168.199.; do ping -c1 $ & done
More or less the same is achieved if you use a special scan type of nmap with
$ sudo nmap -sn -PE -n 192.168.179.1-254
That is also my recommended way of probing since you can fine tune the way you ask the clients for their MAC addresses.
ping multiple IP’s using bash?
I have 10 IP numbers which I have to ping daily for checking , How I can do that by using BASH script. So that I can automate that task by using cron. I want BASH script only. Thank you.
Below answer I have mentioned IP’s of Google,yahoo,msn etc. I have tried that myself. Inserting <> and , are not working here between IP’s to separate them. hope it may help somebody in future. Thank you for reading.
7 Answers 7
As your ip range has no symmetry and there are only 10 nodes, I would suggest to list them in a text file. I am considering the file containing the list is list.txt which contains list of ip one at each line as shown below,
10.12.13.14 172.15.48.3 192.168.45.54 . 48.114.78.227
#!/bin/bash # Program name: pingall.sh date cat /path/to/list.txt | while read output do ping -c 1 "$output" > /dev/null if [ $? -eq 0 ]; then echo "node $output is up" else echo "node $output is down" fi done
To update the running status of your nodes at an interval of 30 mins use at crontab,
*/30 * * * * /path/to/pingall.sh > /path/to/log.txt
$ cat /path/to/log.txt Fri Jan 31 15:06:01 IST 2014 node 10.12.13.14 is up node 172.15.48.3 is up node 192.168.45.54 is up . node 48.114.78.227 is down
this seems exactly what OP should be looking for.. and since websites like google.com, yahoo.com, etc. use multiple servers to handle requests it would be better to ping them with their domain names (so that you possibly won’t have to change the IP in your ping-list the coming week)..
#!/bin/bash for i in `seq $ $` do ping -c 1 $.$ > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "$.$ responded." else echo "$.$ did not respond." fi done
To run ./script 192.168.1 0 10 for example this will ckeck the ips 192.168.1.0 to 192.168.1.10 and echo responded if ping is ok and didn’t respond if not.
NB: You can replace $1 $2 $3 by static variables if the range and the IP’s are always the same.
A neat and simple script that could be very useful (i.e: on embedded devices), even when it does not address 100% the conditions of the question. Thanks you. +1 deserved.
Assume that you have 5 IP’s( to reduce the answer only) then you can ping them with
#!/usr/bin/bash for i in xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxxx do ping -c 5 $i done
Note: Not curl brackets , No Commas(,) between IP’s.
[raja @ scripts]$ cat ping.sh for i in 74.125.236.70 98.139.183.24 65.55.206.228 91.189.94.156 198.252.206.24 do ping -c 5 $i done [raja @ scripts]$ ./ping.sh PING 74.125.236.70 (74.125.236.70) 56(84) bytes of data. 64 bytes from 74.125.236.70: icmp_seq=1 ttl=128 time=11.5 ms 64 bytes from 74.125.236.70: icmp_seq=2 ttl=128 time=11.0 ms 64 bytes from 74.125.236.70: icmp_seq=3 ttl=128 time=10.9 ms 64 bytes from 74.125.236.70: icmp_seq=4 ttl=128 time=16.5 ms 64 bytes from 74.125.236.70: icmp_seq=5 ttl=128 time=18.2 ms --- 74.125.236.70 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4025ms rtt min/avg/max/mdev = 10.966/13.682/18.291/3.120 ms PING 98.139.183.24 (98.139.183.24) 56(84) bytes of data. 64 bytes from 98.139.183.24: icmp_seq=1 ttl=128 time=244 ms 64 bytes from 98.139.183.24: icmp_seq=2 ttl=128 time=253 ms 64 bytes from 98.139.183.24: icmp_seq=3 ttl=128 time=255 ms 64 bytes from 98.139.183.24: icmp_seq=4 ttl=128 time=251 ms 64 bytes from 98.139.183.24: icmp_seq=5 ttl=128 time=243 ms --- 98.139.183.24 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4251ms rtt min/avg/max/mdev = 243.511/249.623/255.275/4.674 ms PING 65.55.206.228 (65.55.206.228) 56(84) bytes of data. From 10.22.96.94 icmp_seq=5 Packet filtered --- 65.55.206.228 ping statistics --- 5 packets transmitted, 0 received, +1 errors, 100% packet loss, time 14002ms PING 91.189.94.156 (91.189.94.156) 56(84) bytes of data. 64 bytes from 91.189.94.156: icmp_seq=1 ttl=128 time=240 ms 64 bytes from 91.189.94.156: icmp_seq=2 ttl=128 time=240 ms 64 bytes from 91.189.94.156: icmp_seq=3 ttl=128 time=240 ms 64 bytes from 91.189.94.156: icmp_seq=4 ttl=128 time=240 ms 64 bytes from 91.189.94.156: icmp_seq=5 ttl=128 time=240 ms --- 91.189.94.156 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4242ms rtt min/avg/max/mdev = 240.060/240.222/240.309/0.626 ms PING 198.252.206.24 (198.252.206.24) 56(84) bytes of data. 64 bytes from 198.252.206.24: icmp_seq=1 ttl=128 time=237 ms 64 bytes from 198.252.206.24: icmp_seq=2 ttl=128 time=237 ms 64 bytes from 198.252.206.24: icmp_seq=3 ttl=128 time=237 ms 64 bytes from 198.252.206.24: icmp_seq=4 ttl=128 time=237 ms 64 bytes from 198.252.206.24: icmp_seq=5 ttl=128 time=242 ms --- 198.252.206.24 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4251ms rtt min/avg/max/mdev = 237.600/238.575/242.291/1.933 ms
How to ping all the ip in LAN using Terminal?
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 4
You can install an application called nmap .
Then you can check your entire network for all connected IP addresses by typing in the following:
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:
A typical scan might return something like the following:
terrance@terrance-ubuntu:~$ nmap -sP 10.0.0.1/24 Starting Nmap 6.40 ( http://nmap.org ) 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