Register
It is currently Tue Jul 22, 2014 9:25 am

Need help!


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Tue Aug 05, 2008 5:48 am   

Joined: Tue Aug 05, 2008 5:20 am
Posts: 3
Location: Sydney
Hey everyone!
I need a ping sweep script that will ping all IP addresses in the range 10.23.1.0 to 10.23.1.253.
Thanks for your help.


Top
 Profile  
 PostPosted: Tue Aug 05, 2008 10:08 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
i strongly suggest you use nmap

http://nmap.org/

nmap -sP 10.23.1.0/24


Top
 Profile  
 PostPosted: Tue Aug 05, 2008 4:52 pm   

Joined: Tue Aug 05, 2008 5:20 am
Posts: 3
Location: Sydney
The thing is, I cannot use that program (nmap), bash script is a part of contract.


Top
 Profile  
 PostPosted: Tue Aug 05, 2008 5:59 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
use a for loop


Top
 Profile  
 PostPosted: Wed Aug 06, 2008 2:41 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Australian wrote:
The thing is, I cannot use that program (nmap), bash script is a part of contract.


Isn't a bash script mostly a way to connect together other software :lol:

Code:
#!/bin/bash

nmap -sP 10.23.1.0/24


You could add your own echos or process the output a little to make it look good but nmap is the sane way to do it as that's what it's designed to do. It's extremely unlikely that any bash script yourself or we could write will perform anything like as well.

Code:
#!/bin/bash

for hip in $(seq 1 253); do
  ping -c 1 10.23.1.${hip}
done


That'll do it but the output will be crap and it'll take longer and be less accurate.
Using scripting is for making life easier not more complex ^^


Top
 Profile  
 PostPosted: Wed Aug 06, 2008 10:52 pm   

Joined: Tue Aug 05, 2008 5:20 am
Posts: 3
Location: Sydney
Thanks everyone!


Top
 Profile  
 PostPosted: Thu Aug 28, 2008 1:44 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Here's my extremely late contribution! I wrote this a couple of years ago when I was running a test lab without a lot of cooperation from the IT department when it came to asking which IPs were available... I'd run this script to find an available IP on our "static" range (shared with several other departments), pick an available IP, and ask for forgiveness if it turned out somebody had it "reserved". Here goes!

Code:
#!/bin/sh

if [ $# != 3 ]; then
  echo "usage: ipfree.sh <first three octets> <start> <end>"
  exit
fi

NET="$1"
START="$2"
END="$3"

for RANGE in $(seq $START $END); do
  FREE=$(ping -c1 $NET.$RANGE | grep -Eo '[0-1] received')
  if [ "$FREE" == "0 received" ]; then
    echo "$NET.$RANGE - available"
  elif [ "$FREE" == "1 received" ]; then
    echo "$NET.$RANGE - in use"
  fi
done


It's a little messy, but I hope it helps someone!

-Jeo


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 7 guests


You cannot post new topics in this forum
You cannot 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:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP