[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cobalt-users] RAQ2 Script to List in use IP Addresses



Thanks to everyone that offered help on this.
As a RAQ 2 owner, it's a pain to have to figure out which
is the next available IP address from the GUI.
So I wrote this very simple script that is easy to understand.

It will highlight the next unused IP address in sequence
with Red text.

If you install it in /home/sites/www.somesite.com/admin/IPLister.cgi
Then you can run it from a web browser.

If you give it the parameter of the first real IP address then it
will not highlight prior addresses, but you can leave of the param.
So you could call it as
http://www.mysite.com/admin/IPLister.cgi?100
or
http://www.mysite.com/admin/IPLister.cgi
Both will work.

(See notes at end of msg for warnings on using this)


Cut it here-->
#!/usr/bin/perl
#Script by Paul Alcock Agility Systems, Inc.
#September 2000
#webmgr@xxxxxxxxxxxxxxxxxx


print "Content-type: text/html\n\n";
system "/sbin/ifconfig | grep 'inet addr' | cut -f 2 -d':' | cut -f 1 -d' '
> list.dat";
open (LIST,'list.dat');
	while(<LIST>){
		chomp($_);
		($Field1,$Field2,$Field3,$Field4)=split(/\./,$_);
		$IPList[$i]=$Field4;
		$i++;
	}
close(LIST);
@SortedIPList=sort bynumber @IPList;
print "IP List<br>Available Inet Addresses are in <font
color='red'>Red</font><br>";
	$First=1;
	for ($i=0;$i<=$#SortedIPList;$i++){
		if ($SortedIPList[$i] >$ARGV[0] && $SortedIPList[$i] >
$SortedIPList[$i-1]+1){
			print "<font color='red'><b>Inet Addr: $Field1.$Field2.$Field3.";
			print $SortedIPList[$i-1]+1;
			print "</font></b><br>";
			$First=0;
		}
		print "Inet Addr: $Field1.$Field2.$Field3.$SortedIPList[$i]<br>";
	}

print "<br><b>Last Inet Address in use is
$Field1.$Field2.$Field3.$SortedIPList[$#SortedIPList]<br>All done<br></b>	";

sub bynumber{
	$a<=> $b;
}

<-- cut it here


Note:
This is free, unfettered, and unwarranted. Take it as it and use it as you
wish.
The usual safety notes apply (keeping my butt safe).
I do not expect this script to do anything other than what is stated above,
and then at your own risk.
I would not give the script a name that anyone could easily figure out. They
may get some kick
out of figuring out what your next ip address is.
So you should probably name it as '__SomeWeirdName.cgi' or whatever.

this script could probably have been written more succinctly, but..
whatever.

Paul