Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Fri Dec 01, 2023 1:17 am


Internet Protocol, Transport Control Protocol, Network protocols, Routing, Routers, IP aliases, Routes, Ethernet

Author Message
mandrei99
Post  Post subject: FreeBSD and Linux: How to find live hosts on a directly connected subnet with ping  |  Posted: Mon Jan 12, 2015 9:24 am

Joined: Tue Aug 04, 2009 9:16 am
Posts: 250

Offline
 

FreeBSD and Linux: How to find live hosts on a directly connected subnet with ping

How to find mac address of all hosts in a connected subnet using "ping" / how to find live hosts on a directly connected subnet

Some systems do not have advanced tools for network scanning discovery like nmap, just the basic "ping". Under FreeBSD and Linux a ping while loop can be used to send requests to all hosts in a specific subnet and then to check the arp table entries:

To acomplish this ping while loop in the most efficient way, I'm interested in two ping options: "-W 1"and "-c 1":
Quote:
usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]
[-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]
[-P policy] [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]
[-W waittime] [-z tos] host
ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]
[-M mask | time] [-m ttl] [-P policy] [-p pattern] [-S src_addr]
[-s packetsize] [-T ttl] [-t timeout] [-W waittime]
[-z tos] mcast-group


So send only one ping request to each host and wait one second for the reply, instead of the default 10-11 seconds timeout in Linux and FreeBSD.

Ping while loop to find out alive hosts in Linux and FreeBSD:
Code:
# i=1; while [ $i -lt "255" ] ; do ping -c 1 -W 1 192.168.0.${i} >/dev/null; i=`expr $i + 1`;  done


This command will take at most 254-255 seconds
Now, we're not interested in the ping replies as some hosts could block ICMP packets, but we're interested in the mac entries in the arp table of the host (remember the target subnet is directly connected):

Code:
# arp -an | grep -v incomplete
? (10.1.10.2) at 00:1c:39:2a:32:ba on vmx1 permanent [ethernet]
? (192.168.0.65) at bc:8e:a4:ea:1a:e3 on vmx0 expires in 818 seconds [ethernet]
? (192.168.0.1) at 3c:21:72:c6:c1:88 on vmx0 expires in 1195 seconds [ethernet]
? (192.168.0.154) at 00:0c:39:61:39:17 on vmx0 expires in 123 seconds [ethernet]
? (192.168.0.152) at 00:1c:39:16:b8:b9 on vmx0 expires in 849 seconds [ethernet]
? (192.168.0.153) at 00:1c:39:52:07:bb on vmx0 expires in 490 seconds [ethernet]





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "FreeBSD and Linux: How to find live hosts on a directly connected subnet with ping"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. How to block ping icmp echo requests without a firewall in Linux

debuser

0

2776

Mon Nov 26, 2012 9:46 am

debuser View the latest post

There are no new unread posts for this topic. FreeBSD find pid that opened TCP/UDP socket without lsof using address of protocol control block(PCB

mandrei99

0

3362

Wed Dec 11, 2013 4:56 am

mandrei99 View the latest post

There are no new unread posts for this topic. Junos: How to add static host mapping (/etc/hosts) in Junos configuration

mandrei99

1

3236

Wed Nov 26, 2014 7:22 am

killdill045 View the latest post

There are no new unread posts for this topic. Set up FTP PROXY via command line in Linux/FreeBSD

mandrei99

0

22856

Tue Jan 20, 2015 5:01 pm

mandrei99 View the latest post

There are no new unread posts for this topic. Set up HTTP PROXY for shell internet access Linux/FreeBSD

mandrei99

0

66038

Tue Jan 20, 2015 4:59 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to add IP alias in Debian Linux to last after reboot

debuser

3

4949

Sat Jul 21, 2012 6:03 am

Harespok View the latest post

There are no new unread posts for this topic. Linux: How to list IPv6 neighbors

mandrei99

0

3850

Thu Oct 09, 2014 3:11 am

mandrei99 View the latest post

There are no new unread posts for this topic. How to add (persistent) static ARP entries in Linux

mandrei99

0

31055

Mon Sep 29, 2014 5:17 am

mandrei99 View the latest post

There are no new unread posts for this topic. Linux How to change hardware MAC address of an interface

debuser

1

3595

Tue Dec 06, 2011 6:26 am

Zettie49 View the latest post

There are no new unread posts for this topic. DNS reverse lookup in Windows 7 and Linux using - nslookup

mandrei99

0

5937

Tue Jan 13, 2015 8:31 pm

mandrei99 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
cronNews News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO