map of assigned networks
Willi Huber huber at chx400.switch.ch
Tue May 24 13:35:32 CEST 1994
Hallo,
prior to the past RIPE meeting I sent a (rather long) message onto this
list about a 'graphical' representation of the assigned networks from the
blocks 193/8 - 194/8. Nandor Horvath has asked me to make available the script
that generated this output. Here it is. Make with it whatever you like.
Willi Huber
--------------
An example:
netmap 193.5/16 <ripe.db
netmap: looking for networks 193.5.0 <= network < 193.6.0
193.005.000 .*#*#...**##****#*#*#*#*#*##*#*#****#*#*#*#*##**#*#*#*##**#.*#*#
193.005.064 ....**##****####*#*#*#*#********#*#*#*#*#*#*####****####*#*#*#**
193.005.128 ################******..####****#####...****##**##*#************
193.005.192 ########################********################**********#.*#*
--------------
#!/bin/perl
$c = "*";
$counter = 65;
$arg = shift(@ARGV);
if ($arg =~ /^\d+.*\/\d+$/) {
($firstnet,$bits) = split(/\//,$arg);
} else { $bits = 32; }
&binnet($firstnet);
$bits = 24-$bits;
if ($bits < 0) { print <<"end_of_text"; exit; }
Usage: netmap net/bits file
net/bits: the range of network addresses to be analysed
file: the input file in the format of the ripe.db.
If file is omitted, STDIN is read
example: netmap 193/8 ripe.db
NOTE: this script does not run propperly for class B addresses, use it
only with calss C's.
end_of_text
$mask = 1;
while ($bits-- > 0) { $mask *= 2; }
$firstnet = int($firstnet / $mask) * $mask;
$lastnet = $firstnet+$mask;
print "\nnetmap: looking for networks ";
&printnet($firstnet);
print " <= network < ";
&printnet($lastnet);
print "\n\n";
open(INET,">/tmp/netmap.$$") || die "netmap: Couldn't open >/tmp/netmap.$$\n";
while (<>) {
if (/\*in/) {
chop;
($key,$value) = split(/\s+/,$_,2);
if ($value =~ /-/) {
($value,$value2) = $value =~ /(\S+) - (\S+)/;
&binnet($value); &binnet($value2);
} else {
&binnet($value);
$value2 = $value;
}
if (($value >= $firstnet) && ($value < $lastnet)) {
printf INET "%09d %09d\n",$value,$value2;
}
}
}
close INET;
$lastplotted = $firstnet-1;
open(SORTED,"sort /tmp/netmap.$$ |") ||
die "netmap: Couldn't open sort /tmp/netmap.$$ |\n";
while (<SORTED>) {
($value,$value2) = split;
&plot($value,$value2);
}
print "\n";
close SORTED;
unlink("/tmp/netmap.$$");
exit;
sub binnet {
undef(@bytes);
(@bytes) = split(/\./,$_[0]);
$_[0] = ($bytes[0]*256+$bytes[1])*256+$bytes[2];
}
sub printnet {
local($i) = $_[0];
printf "%d.%d.%d",
int($i / 0x10000),
int($i / 0x100 % 0x100),
$i % 0x100;
}
sub plot {
local($v,$v2) = @_;
if ($lastplotted >= $v) { return; }
$lastplotted++;
while ($lastplotted != $v) {
&plotnet(".",$lastplotted);
$lastplotted++;
}
&plotnet($c,$v);
while ($v != $v2) {
$v++;
&plotnet($c,$v);
}
$lastplotted = $v2;
if ($c eq "*") { $c = "#"; } else { $c = "*" }
}
sub plotnet {
local($c,$i) = @_;
if ($counter >= 64) {
printf "\n%03d.%03d.%03d ",
int($i / 0x10000),
int($i / 0x100 % 0x100),
$i % 0x100;
$counter = 0;
}
$counter++;
print $c;
}
[ lir-wg Archives ]