The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash Script to check Remote Host Connection zulfikarmd UNIX for Dummies Questions & Answers 5 04-16-2008 07:53 AM
How to delete the files from local host to remote host krishna176 SUN Solaris 3 03-24-2007 04:48 PM
disk discovery fredao SUN Solaris 2 01-08-2007 01:51 PM
host alias not working: host not found FunnyCats UNIX for Advanced & Expert Users 4 05-13-2005 05:36 PM
QNX host cannot ping SCO host, vice versa gavon IP Networking 2 08-20-2001 09:57 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-15-2008
bronkeydain bronkeydain is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
host discovery using bash

I am trying to make a bash script to scan subnets to see what hosts are available. Is it correct that you can not make the ping command time out less than a second? The script below works, but can take up to 255 seconds which is a bit long Is there a way to solve this using bash only?

<code>
subnet=192.168.2.
addr=1
while [ $addr -lt 256 ]; do
ping -c 1 -t 1 $subnet$addr > /dev/null && echo Found $subnet$addr
let addr=addr+1
done
</code>
  #2 (permalink)  
Old 03-17-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
I think I saw a program called "uping" or "mping" which had more fine-grained timing controls (I think part of the MRTG suite ... could have been "fastping" too).

Two other ideas come to mind.

1. Run asynchronously. Spawn off a big bunch of pings and even if some of them take one second or more, the whole bunch will finish in one or two seconds (provided you have the CPU and bandwidth to run enough of them in parallel).

Code:
subnet=192.168.2.
for addr in `seq 1 1 255 `; do
  ( ping -c 1 -t 1 $subnet$addr > /dev/null && echo Found $subnet$addr ) &
done
2. Is ping really what you want? If you have a hunch about a port you could expect to be open, netcat could do this much faster (and probably produce more accurate results -- the fact that ping works doesn't really mean the host is up and working correctly).
  #3 (permalink)  
Old 03-17-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
I think this is the "fast ping" I was thinking of. fping.com Looks like it can handle the whole problem you have.

It's used by a system called SmokePing, by the MRTG author, wich is however apparently a separate module. SmokePing - Smokeping::probes::FPing
  #4 (permalink)  
Old 03-23-2008
bronkeydain bronkeydain is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
Era, I am so sorry for the late reply.

Your script is perfect! Thanks very much for the input.
I really just want to know where my machines are on the network . My DHCP server is so basic that it does not even show me the current leases.

Last edited by bronkeydain; 03-23-2008 at 09:26 PM.. Reason: fix typo
  #5 (permalink)  
Old 03-24-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
If it's your network then you could also simply do a ping to the broadcast address, although I guess a some modern machines will no longer respond to broadcast ping (at least it's an option).
  #6 (permalink)  
Old 03-24-2008
s4g3's Avatar
s4g3 s4g3 is offline
Registered User
  
 

Join Date: Nov 2007
Location: India
Posts: 43
If i were you, i would have nmap

~s3g4
Closed Thread

Bookmarks

Tags
ping, ping port, port, port ping

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0