I work for an ISP, one of our services is an X.400 ADMD which
has multiple (100s) connections to the outside world, throught VPNs,
framerelay connections, and `normal` Internet connections
Our Application managers wished to see actually HOW the IP connections
left our network.
The information on adjacent MTAs is kept in a file with the format:
MTA=
MTAName=NAME
bla bla=bla
bla bla=bla
...
Addr=<IP Address OR X.25 Address>
...
...
EndMTA
This file was used as input
I whipped up the following in 20 mins, it traceroutes
to our network boundry, resolves network objects, and prints the
route the connection takes (IP addresses, and object names changed
to protect the `innocent`)
#!/usr/bin/perl -w
use strict;
$/="EndMTA";
my %Address;
my %Resolve;
$Resolve{'10.0.0.10'}='Screening_Router';
$Resolve{'10.0.0.15'}='Firewall_1';
$Resolve{'10.0.0.20'}='Firewall_2';
$Resolve{'10.0.0.25'}='Internet_Router';
$Resolve{'10.0.0.30'}='Router_06';
$Resolve{'10.0.0.35'}='Router_05';
$Resolve{'10.0.0.40'}='Router_03';
$Resolve{'10.0.0.45'}='Router_01';
$Resolve{'10.0.0.50'}='Router_11';
while (<>)
{
next unless /MTAName=(\S+).*Addr=(\d+\.\d+\.\d+\.\d+)/so;
$Address{$1}=$2;
};
$/="\n";
for my $Mta (sort keys %Address)
{
my @Data=`traceroute -n -m 3 $Address{$Mta} 2> /dev/null`;
next unless @Data==5;
my @Hop;
push @Hop,(split /\s+/,$_)[2] for ($Data[-3],$Data[-2],$Data[-1]);
print "$Mta ($Address{$Mta}):\t";
print "\t=>\t$_(",$Resolve{$_}||'Unknown',")" for @Hop;
print "\n";
};
I love Perl for quick hacks, and bigger projects... this was a fun hack ;)
GreetZ!,
print "profeth still\n" if /bird|devil/;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.