Commit fd9074d4 authored by Mac Newbold's avatar Mac Newbold

ifconfig scripts.

parent 4d85de1a
#Use this file as input to ifc_all - # is comment line,
# Machine IP |if#| New IP for the interface
# -----------------------------------------
155.99.214.101 0 192.168.1.1
155.99.214.101 1 192.168.2.1
155.99.214.101 2 192.168.3.1
155.99.214.101 3 192.168.4.1
155.99.214.102 0 192.168.1.2
155.99.214.102 1 192.168.2.2
155.99.214.102 2 192.168.3.2
155.99.214.102 3 192.168.4.2
155.99.214.103 0 192.168.1.3
155.99.214.103 1 192.168.2.3
155.99.214.103 2 192.168.3.3
155.99.214.103 3 192.168.4.3
155.99.214.104 0 192.168.1.4
155.99.214.104 1 192.168.2.4
155.99.214.104 2 192.168.3.4
155.99.214.104 3 192.168.4.4
155.99.214.105 0 192.168.1.5
155.99.214.105 1 192.168.2.5
155.99.214.105 2 192.168.3.5
155.99.214.105 3 192.168.4.5
155.99.214.106 0 192.168.1.6
155.99.214.106 1 192.168.2.6
155.99.214.106 2 192.168.3.6
155.99.214.106 3 192.168.4.6
155.99.214.107 0 192.168.1.7
155.99.214.107 1 192.168.2.7
155.99.214.107 2 192.168.3.7
155.99.214.107 3 192.168.4.7
155.99.214.108 0 192.168.1.8
155.99.214.108 1 192.168.2.8
155.99.214.108 2 192.168.3.8
155.99.214.108 3 192.168.4.8
155.99.214.109 0 192.168.1.9
155.99.214.109 1 192.168.2.9
155.99.214.109 2 192.168.3.9
155.99.214.109 3 192.168.4.9
155.99.214.110 0 192.168.1.10
155.99.214.110 1 192.168.2.10
155.99.214.110 2 192.168.3.10
155.99.214.110 3 192.168.4.10
#!/usr/bin/perl
if ( $#ARGV < 0) {
die("Usage: ifc_all <ifc_file>\n");
}
open(WHO,"/usr/bin/whoami 2>&1 |");
$_ = <WHO>;
chop;
if ($_ ne "root") { die("This won't work unless you're root.\n"); }
if (-e "$ARGV[$0]" ) {
open(IN,$ARGV[$0]) || die("Couldn't open $ARGV[$0]\n");
} elsif (-e "/usr/testbed/etc/$ARGV[$0]") {
open(IN,"/usr/testbed/etc/$ARGV[$0]") ||
die("Couldn't open /usr/testbed/etc/$ARGV[$0]\n");
} else {
die ("Couldn't locate $ARGV[$0]\n");
}
my $last = "";
my $OS = "";
my $IP = "";
my $IF = 0;
my $ifstr = "";
my $newIP = "";
print "Reading input file...\n";
while (<IN>) {
chop;
s/\#(.*)//;
if ($_ eq "") {next;}
#print "Got $_\n";
($IP,$IF,$newIP)= split(" ",$_);
#print "Config $IP, interface $IF, to IP $newIP\n";
#if its not the same as the last one, get the OS
if ( $IP ne $last ) {
$last = $IP;
if (-e "/bin/ping") {
open(PING,"/bin/ping -c 1 $IP 2>&1 |");
} else {
open(PING,"/sbin/ping -c 1 $IP 2>&1 |");
}
do { } until ( <PING> =~ /transmitted, (\d*) packets received/ );
print "Got $1 ping packet(s) back from $IP.\n";
if ( $1 > 0 ) {
open(UNAME,"rsh $IP uname -a 2>&1 |");
$_ = <UNAME>;
#print $_;
if ($_ ) { @temp = split(" ",$_); $OS = $temp[$0]; }
} else {
$ifstr="";
}
print "OS for $IP is $OS \t";
if ($OS eq "Linux") { $ifstr="eth"; }
elsif ($OS eq "FreeBSD") { $ifstr="fxp"; }
else { $ifstr = ""; }
if ($ifstr) { print "Using interface string \"$ifstr\"\n"; }
}
#Set up the interface
if ( $ifstr eq "" ) {
print "Unknown OS $OS on $IP. Skipping interface $IF.\n";
next;
}
print "Setting $IP $ifstr$IF to $newIP...\n";
open(IFC,
"rsh $IP /sbin/ifconfig $ifstr$IF inet $newIP ".
"netmask 255.255.255.0 2>&1 |"
);
while ( <IFC> ) {
print ">> $_";
}
}
#!/bin/csh
#
# ifc_filegen
#
# Generates files for setting up interfaces (NICs) of testbed machines
#
# Range of machines to work with
if ($1 > 0) then
set first=$1
else
set first=1
endif
if ($1 > 0) then
set last=$2
else
set last=10
endif
if ( -e /home/newbold/bin ) then
set machines=`/home/newbold/bin/range $first $last`
else if ( -e /users/newbold/bin ) then
set machines=`/users/newbold/bin/range $first $last`
else
set machines
set i=$first
while ( $i <= $last )
set machines = "$machines $i"
set i=`expr $i + 1`
end
endif
# Usually use 192.168 (unroutable Internet testing subnet)
if ($3 > 0) then
set subnet=$3
else
set subnet=192.168
endif
echo "#Use this file as input to ifc_all - # is comment line,"
echo "# Machine IP |if#| New IP for the interface"
echo "# -----------------------------------------"
foreach m ( $machines ) # for each machine
#Control net IPs are 101, 102, ...
set control=`expr 100 + $m`
foreach i ( 0 1 2 3 ) # for each interface
# set newip=`expr $last \* $i + $m`
set newnet=`expr $i + 1`
#output a line with Control IP, interface, and IP for that interface
echo 155.99.214.$control $i $subnet.$newnet.$m
end
end
#clean up...
unset m i first last control newip last machines subnet newnet
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment