Finding All Hosts On the LAN From Linux / Windows Workstation

by Vivek Gite [Last updated: March 5, 2008]

Q. How do I find out if all host computers on the LAN are alive or dead from a Linux or Windows XP computer? My network subnet range is 192.168.1.0/24 and I'm using dual boot Debian Linux / XP SP2 computer.

A.You can use normal ping command and shell script loop statement to print the list of all LAN computers from a shell prompt.

Linux / UNIX one liner to ping all hosts on the LAN

Type the following command, enter:
$ for ip in $(seq 1 254); do ping -c 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo "192.168.1.$ip UP" || : ; done
Output:

192.168.1.1 UP
192.168.1.1 UP
192.168.1.2 UP
192.168.1.5 UP
......
...
..
192.168.1.254 UP

See previous article: Simple Linux and UNIX system monitoring with ping command and scripts.

A Note About Windows Workstation

If you are using Windows 2000 / XP / Vista, try something as follows at DOS / NT command prompt (Start > Run > CMD > Enter key):
c:> for /L %I in (1,1,254) DO ping -w 30 -n1 192.168.1.%I | find "Reply"
Read cmd.exe help page and batch scripting documentation for more information.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 12 comments… read them below or add one }

1 Casper 03.05.08 at 6:37 pm

You would probably use
"for ip in $(perl -e '$,="\n"; print 0 .. 8;') ; do ping -c 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo “192.168.1.$ip UP” || : ; done”
on non GNU/Linux system, as seq does not exist on Solaris and OSX.

2 Casper 03.05.08 at 6:41 pm

Ups, this is nicer, and faster.
for ip in $(perl -e '$,="\n"; print 1 .. 254;') ; do ping -t 1 -c 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo “192.168.1.$ip UP” || : ; done

I’ve added a 1 sec. timeout on ping.

3 richard 03.05.08 at 8:28 pm

Do you know fping ?
$ sudo apt-get install fping
$ fping -a -g 192.168.1.0/24 2> /dev/null

4 vivek 03.05.08 at 9:27 pm

@Casper,
Thanks for sharing perl only code.

@Richard,
Sure, fping was covered some time ago..

5 Scott Carlson 03.06.08 at 2:41 am

I generally just use this “ping -b 192.168.1.255″ Which broadcasts a ping to the whole network at once.

6 Topper 03.06.08 at 8:38 am

What about Windows machines with MS firewall which default forbid ICMP replay ?
Maybe must use ARP cache after ping

7 Z3n0 03.06.08 at 9:30 am

another way…

for ((ip=1;ip/dev/null; [ $? -eq 0 ] && echo “192.168.1.$ip UP” || : ; done

8 matthias 03.06.08 at 9:40 am

If a host on your local network won’t answer on a ping request you could try arping, which does an arp request.
arping 192.168.1.1
ARPING 192.168.1.1 from 192.168.1.226 eth0
Unicast reply from 192.168.1.1 [00:01:02:xx:xx:xx] 0.668ms

Another method is simply using nmap:
nmap -sP 192.168.1.0/24

9 Z3n0 03.06.08 at 10:13 am

Something wrong with prev. comment… (< and > char)

for (( ip=1 ; ip<=254 ; ip++ )); do ping -c 1 -t 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo “192.168.1.$ip UP” || : ; done

10 phillip 03.07.08 at 12:42 pm

Using nast ?

http://netsecure.alcpress.com/nast/

nast -m

best.

11 sg 03.07.08 at 4:29 pm

another option is installing arpwatch.

12 suren 03.16.08 at 4:28 am

wont this command do ???

nbtscan 10.0.0.1-125

this checks all the computers whose ip address are in the range of 10.0.0.1 to 10.0.0.125 and displays only those which are ON and connected to the network !

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , ,

Previous post: Linux / UNIX: List Open Files for Process

Next post: Is There a UNIX / Linux unerase / undelete Command?