Sponsored Content
Top Forums Shell Programming and Scripting Bash script to test IP range on server Post 302466018 by dgerman on Monday 25th of October 2010 07:50:26 AM
Old 10-25-2010
You might be looking for something really simple like this:
(more of a learning experience that useful, but easy to understand)
Code:
export subnet=1
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14     17 18 19 20 21 22 23 24 25 26 27 28 29 30
do
echo  "      192.168.$subnet.$i "
/sbin/ping -c 1 -w 1   192.168.$subnet.$i
done

save the above in a file named pingall.sh
then chmod +x pingall.sh this sets the permissions allowing you to eXecute the scipt
then ./pingall.sh

You might find my version of the documentation of chmod helpful
real-world-systems com/docs/chmod.1.html
also
real-world-systems com/docs/ping.1.html

A more complicated and much faster version:
Code:
#!/bin/bash
#PING smacker.local (192.168.0.7): 56 data bytes
#64 bytes from 192.168.0.7: icmp_seq=0 ttl=64 time=0.120 ms
#
#--- smacker.local ping statistics ---
#1 packets transmitted, 1 packets received, 0% packet loss
#round-trip min/avg/max/stddev = 0.120/0.120/0.120/0.000 ms
# just get sudo to ask for password sooner
sudo echo -n "$HOSTNAME  "

export subnet=`sudo /sbin/ping -l 3 -c 1  $HOSTNAME  | egrep "ms" | grep -v 100% |sed "s/64 bytes//" | sed "s/icmp_//" | sed "s/\.... ms//"  | sed "s/round.*//"  |sed "s/from//"| grep -v " 0% packet loss" | sed s"/: seq=. ttl=.4 time=.//" |cut -f3 -d\.`

ping $HOSTNAME
echo "++subnet $subnet"

for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 17 18 19 20 21 22 23 24 25 26 27 28 29 30
do
echo  "      192.168.$subnet.$i " 
#       alert    need at least 3 to get min/max average stdDev preload  -l 3  -c 3  uniq only sees first one!
sudo /sbin/ping -A -c 3 -l 3   192.168.$subnet.$i  | egrep "ms" | grep -v 100% |\
sed "N; s/\n/   /;s/64 bytes from/   from/g; s/ttl=.. /& /g; s/icmp_seq=.//g ; s/\/.....\/.....\/+0.00. ms//; s/\/.....\/.....\/nan//; s/\/stddev/ stddev/;s/\/0./ ./g; s/. ms/ms/g ; s/ .\.... \.... \.... .0[01]ms/ms/; s/ \.00ms/ms/; s/   round/ round/g" | grep -v " 0% packet loss" |grep -v "^$" |uniq &

host 192.168.$subnet.$i | grep -v NXDOMAIN | \
      sed "s/in-addr.arpa//; s/ domain name pointer// ; s/^./                &/" &
sleep 0

#sudo /sbin/ping -A -l 3 -c 3    192.168.1.$i  | egrep "ms" | grep -v 100% |sed "N; s/\n/   /;s/64 bytes from/   from/; s/ttl=.. /& /; s/icmp_seq=.// ; s/0.000/ 0/; s/\/.....\/.....\/nan//" | grep -v " 0% packet loss" |grep -v "^$" &

done

#sleep 1
for i in  6   4  2  
do
sleep 2
echo -n $i " processes still running: " ; /bin/ps | wc -l
done
sleep 2
 echo $PS1

Please let us know how you do.

Moderator's Comments:
Mod Comment Use code tags, please...

Last edited by Scott; 10-25-2010 at 09:01 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to Test Application Server is running

Hi, I'm a complete novice at Unix and need to create a script that does the following... checks to see if an application server is running. If the app is running then print 'Available' Else print 'Unavaliable' exit from scriopt I have no idea where to start. I'd be very grateful... (0 Replies)
Discussion started by: duglover
0 Replies

2. UNIX for Advanced & Expert Users

execute a script on test server from dev server

I need to execute a script from dev server which is located on Test server.I can use ftp to connect to dev server and from there how can i execute a command on test server. Thanks (5 Replies)
Discussion started by: ukatru
5 Replies

3. Shell Programming and Scripting

Bash Script w/ IP Range

Is there a basic IP range script or a site that has basic script written? I am making a script that is looking for a device on my network threw HTTP://. I and using a for loop with wget to download the page and using grep to search the code for the serial number. My range is 172.16.x.x/16 I... (3 Replies)
Discussion started by: captaindoogles
3 Replies

4. Shell Programming and Scripting

bash script to test network connection - please help

I want to test if my host can connect to any of the following 10 hosts (192.168.1.0 to 192.168.1.9) I didnt know which command i should use, so i chose ping. (i wonder if i should use tracepath or sth else) my code is the following: #!/bin/bash clear firstPart="192.168.1" maxNum="9" ... (2 Replies)
Discussion started by: shadow_boi
2 Replies

5. UNIX for Dummies Questions & Answers

How do i tell my bash shell script to test the output of a command against something

How do i tell my bash shell script to test the output of the command i'm using?? I want this script to look for lines not equal to 1 then let me know.. $ cat blah ; echo ---- ; cat blah.sh 1 fe 1 fi 1 fo 0 fum 1 blahda 1 blah 0 blahh 1 bla 1 bl 1 blahhh ---- #!/bin/bash while... (1 Reply)
Discussion started by: phpfreak
1 Replies

6. Shell Programming and Scripting

Help: Bash backup script (includes copy, test-

Basically it's for a work assignment. Have to make a menu with the following choices ***************menu********************* 1) Show Current Directory 2) Dispaly Current Time and Date 3) Copy 4) Change Password 5) write directory to file 6) Edit File Directory 7) Make backup from... (1 Reply)
Discussion started by: Covax
1 Replies

7. Shell Programming and Scripting

bash script range calculations

Hi, I have data in the following form: AB001 10 AB002 9 AB003 9 etc AB200 5 What I need to do is sum up the second value according to groups of the first, i.e. AB001 to AB030 the total being X, AB031 to AB050 the total being Y etc (there are 5 AB ranges of different sizes). I'm sure... (3 Replies)
Discussion started by: chrissycc
3 Replies

8. Homework & Coursework Questions

Bash Script for Dice Game; Issue with if...else loop to verify user guess is within range

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have written a script for a dice game that: (1) tells user that each of the 2 die are 6 sided (Spots=6); (2)... (3 Replies)
Discussion started by: LaurenRose
3 Replies

9. Shell Programming and Scripting

Bash script - printing range of lines from text file

I'm working on a new exercise that calls for a script that will take in two arguments on the command line (representing the range of line numbers) and will subsequently print those lines from a a specified file. Command line would look like this: ./lines_script.bash 5 15 <file.txt. The script would... (8 Replies)
Discussion started by: ksmarine1980
8 Replies

10. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies
All times are GMT -4. The time now is 09:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy