Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to send one packet to the broadcast address, but wait for all responses.

If I do ping -c 1 192.168.1.255, it sends just one packet, but it quits after getting the first response.

share|improve this question
    
What do you want to do with that command? –  Nils Feb 9 '12 at 21:24
    
@Nils: I just want a quick way to see approximately how many hosts are connected to the network. I know about nmap, but it has been a bit slow in my experience, compared to ping. –  houbysoft Feb 9 '12 at 22:17
1  
Which version of ping? Even on Linux, there are several around. –  Gilles Feb 9 '12 at 22:24
    
@Gilles: this is the standard ping on Mac OS X 10.7.3. I can't seem to find a switch for it to tell its version (tried -v, --version, searching the man page...). –  houbysoft Feb 9 '12 at 22:47
    
Some versions of ping have a -w option to specify a length of time to wait, regardless of how many reply packets have been received. –  jw013 Feb 10 '12 at 4:43
show 2 more comments

2 Answers 2

How would ping know that the responses it got really are all of them?

To find out which hosts on a subnet are up, something like nmap is well suited. See the -sn argument for Host Discovery:

-sn (No port scan)

This option tells Nmap not to do a port scan after host discovery, and only print out the available hosts that responded to the scan. This is often known as a “ping scan”,[...]

Systems administrators often find this option valuable as well. It can easily be used to count available machines on a network or monitor server availability. This is often called a ping sweep, and is more reliable than pinging the broadcast address because many hosts do not reply to broadcast queries.

share|improve this answer
    
I don't really care about "all of them", I just need most. Hence I can ping the broadcast and wait for the responses. I understand that ping has no way of knowing when will all responses arrive, but isn't there a way to specify a time for which it should wait? –  houbysoft Feb 9 '12 at 20:44
    
For example, I can almost achieve what I want by "ping -c2 -i 10 192.168.1.255". It pings the broadcast and waits 10 seconds for the responses. However, in the end it sends another packet. Is there a way to make it wait 10 seconds, but not send anything afterwards? –  houbysoft Feb 9 '12 at 20:45
add comment

This quick check for hosts possibly fails nowadays. There is an increasing number of operating systems that blocks incoming ICMP/ping by default. Perhaps there are better - and possibly faster ways to achieve your goal.

If you have SNMP-read-access to the involved router(s) you might get the information (number of hosts in a network) by a simple SNMP-get-request of the corresponding traffic statistic table.

share|improve this answer
    
Is there a standard command that can be used to query this SNMP? –  houbysoft Feb 11 '12 at 22:54
    
Here is a pack of free tools that help to analyse this data. –  Nils Feb 12 '12 at 21:30
    
Blocking incomming ICMP is a symptom of braindamaged network admin. What most routers do nowadays is to just drop any network packet destined to the broadcast address (that was a popular DoS: send something that gives a sizeable response to the broadcast address forging the victim's address and watch it getting bogged down). –  vonbrand Jan 18 '13 at 0:29
    
@houbysoft sorry - I forgot to address you directly in my comment. –  Nils Jan 19 '13 at 21:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.