Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ping all IPs from it own range (AIX)

Posted on 2011-09-20
7
Medium Priority
?
582 Views
Last Modified: 2013-11-17
OK,

I need a script which take the range of IPs  from the IP and mask on the server it's running and ping, with -c 1 option, theses IPs  to see which responds or not. I would like to exclude the network and braodcast address. I just want to see which IPs are used or not.

NOTE: There's no nmap installed on our AIX boxes. (With nmap -sP uou can do this job)

Thanks..

0
Comment
Question by:sminfo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:MarioAlcaide
ID: 36565721
Hi, you could do this:

subnet=$(echo $begin | sed 's/\.[0-4]*$//')

start=$(echo $begin | sed 's/.*\.//')
stop=$(echo $end | sed 's/.*\.//')

while [[ $start -le $stop ]]
do
  ping -c 1 $subnet.$start
  ((start++))
done
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36565978
Hi,

I don't think we must reinvent the wheel here (at least not as a whole).

So I'll attach two scripts.

The first one is a liittle perl script from (anonymous) internet which would extract
the network address and broadcast address from a given ip/mask combo.

The second is a ksh script I made to ping the IP range between the values found
by the above script, omitting the net and broadcast addresses.

The perl script is called as /usr/local/bin/iprange.pl in the ksh script. Change as desired.

Please note that the ksh script uses the "seq" utility from GNU coreutils
 (http://www.perzl.org/aix/index.php?n=Main.Coreutils)
We could go without it, but this would blow up the ksh script a lot.
Note further the "echo" statement in front of ping. It's for you to test.

Run the script like this:

scriptname ipaddr mask
e.g.
pingrange 192.168.1.1 255.255.255.0

Have fun!

wmp
#!/usr/bin/perl
my $ipaddr=$ARGV[0];
my $nmask=$ARGV[1];
my @addrarr=split(/\./,$ipaddr);
my ( $ipaddress ) = unpack( "N", pack( "C4",@addrarr ) );
my @maskarr=split(/\./,$nmask);
my ( $netmask ) = unpack( "N", pack( "C4",@maskarr ) );
my $netadd = ( $ipaddress & $netmask );
my @netarr=unpack( "C4", pack( "N",$netadd ) );
my $netaddress=join(".",@netarr);

print "Network address : $netaddress \n";

my $bcast = ( $ipaddress & $netmask ) + ( ~ $netmask );
my @bcastarr=unpack( "C4", pack( "N",$bcast ) ) ;
my $broadcast=join(".",@bcastarr);

print "Broadcast address: $broadcast\n";

Open in new window

#!/bin/ksh
/usr/local/bin/iprange.pl $1 $2 | while read line
 do
  echo $line | grep -q "Network" && NET=$(echo $line |awk '{print $NF}')
  echo $line | grep "Network" && set -A beginarray $(echo $line | awk -F":|\\\." '{print $2, $3, $4, $5}')
  echo $line | grep -q "Broadcast" && BRO=$(echo $line |awk '{print $NF}')
  echo $line | grep "Broadcast" && set -A endarray $(echo $line | awk -F":|\\\." '{print $2, $3, $4, $5}')
 done
for s1 in $(seq ${beginarray[0]} ${endarray[0]})
 do
   for s2 in $(seq ${beginarray[1]} ${endarray[1]})
    do
      for s3 in $(seq ${beginarray[2]} ${endarray[2]})
       do
         for s4 in $(seq ${beginarray[3]} ${endarray[3]})
          do
            ADDR=$s1"."$s2"."$s3"."$s4
            [[ $ADDR != $NET && $ADDR != $BRO ]] && echo ping -c1 $ADDR
          done
       done
    done
 done

Open in new window

0
 

Author Comment

by:sminfo
ID: 36566071
Mario,

it didn't work for me:
(aix):[root] /tmp -> ./findip
0821-062 ping: host name . NOT FOUND
./findip[11]: start++: 0403-009 The specified number is not valid for this command.

wmp,

I though there's was a simpler way... I want to run this script inside our IVMs to see the "not used" IPs for our VLANs segments. This IVM does not have coreutils installed. I tried to make the script using pure ksh but I couldn't, mainly because of time . But well, as you said above, it seems I want to reinvent the wheel :-). Come on, show the people your ksh skills.. :-) [joke]
But I suppose it's not easy to do.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36566131
To extract the first ip/mask combo of an IVM:

lstcpip -stored | grep -E "address|Mask" | head -2 | awk '{printf $NF " "} END {print}'

Working on the script ...
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 36566740
Here you go:
#!/bin/ksh
/usr/local/bin/iprange.pl $1 $2 | while read line
 do
  echo $line | grep -q "Network" && NET=$(echo $line |awk '{print $NF}')
  echo $line | grep "Network" && set -A beginarray $(echo $line | awk -F":|\\\." '{print $2, $3, $4, $5}')
  echo $line | grep -q "Broadcast" && BRO=$(echo $line |awk '{print $NF}')
  echo $line | grep "Broadcast" && set -A endarray $(echo $line | awk -F":|\\\." '{print $2, $3, $4, $5}')
 done
s1=${beginarray[0]}; s2=${beginarray[1]}; s3=${beginarray[2]}; s4=${beginarray[3]}
while [[ $s1 -le ${endarray[0]} ]]
 do
   while [[ $s2 -le ${endarray[1]} ]]
    do
      while [[ $s3 -le ${endarray[2]} ]]
       do
         while [[ $s4 -le ${endarray[3]} ]]
          do
            ADDR=$s1"."$s2"."$s3"."$s4
            [[ $ADDR != $NET && $ADDR != $BRO ]] && echo ping -c1 $ADDR
            ((s4+=1))
          done
          ((s3+=1))
          s4=${beginarray[3]}
       done
       ((s2+=1))
       s3=${beginarray[2]}
    done
    ((s1+=1))
    s2=${beginarray[1]}
 done

Open in new window

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 36566804
Finally, here's an example how to get the first ip/mask combo with native AIX (OEM):

ifconfig -a |grep inet | head -1 |awk '{printf "%s %d.%d.%d.%d\n", $2, "0x" substr($4,3,2), "0x" substr($4,5,2), "0x" substr($4,7,2), "0x" substr($4,9,2)}'
0
 

Author Closing Comment

by:sminfo
ID: 36566847
Very nice WMP!!

you rock man!!!

Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question