Hello,

I originally posted a question a couple days ago but I didn't say precisely what I wanted. Many offered good assistance on how I can graphically display a network with GD or GraphViz. Although I've learned a lot about these modules, they are not needed at this time. My problem lies before GD/GrapViz can even be used.

I'm writing a script that takes the output of traceroute and makes a graphical map (CGI, in a web browser) of a network topology. It will distinguish different subnets by the number of hops it takes to reach a certain IP. I would like the final output to look distantly similar to this: http://www.qualys.com/demo/fo_2.9/map-result.html , but not Java or with all that movement/fanciness. See how different subnets/nodes are differentiated? Please read my original post at: http://www.perlmonks.org/index.pl?node_id=108574&lastnode_id=479

My script takes a starting IP and ending IP (i.e., 192.168.0.1 to 192.168.1.254). It then runs traceroute on the first IP, stores all hops in an array (removing everything but the IP), goes to the next IP, and does the same thing to each subsequent IP until it reaches the last IP.

I need to take the output of traceroute each time it is run (already captured in an array with the code directly below), compare it to a previous (array?) route, remove duplicates, and store in an array. Or maybe I could store everything in a huge multidimensional array? Other techniques? All I want to do is to graphically display a network topology. However that is done is fine by me.
my @ip_addrs = map /\(([^)]*)\)/, qx( /usr/sbin/traceroute $target);
HELP!
Adam.
#!/usr/bin/perl -w use CGI qw(:standard); print "Content-type: text/html\n\n"; $first = param("first"); $last = param("last"); &form_check; &validated; sub form_check { #Splits IP addresses (octets) on '.' @first = split(/\./,$first); @last = split(/\./,$last); #THIS IS WHERE $first AND $last ARE CHECKED TO SEE IF THEY ARE #IN PROPER FORM...I CUT THIS CODE OUT TO SHORTEN THIS POST } sub validated { #Calls trace for first IP (only used once) $run_once == 0; while($run_once == 0) { &trace; $run_once++; } #While 3rd octet of $first is less than or equal to 3rd octet of $last +, #and 4th octet of $first is less than or equal to 4th octet of $last while($first[2] <= $last[2] && $first[3] < $last[3]){ #While 4th octet of $first is less than 4th octet of $last while($first[3] < $last[3]){ $first[3]++; #Adds 1 to 4th octet, calls sub trace &trace; } #Is the 3rd octet of $first less than the 3rd of $last? #i.e, 192.168.0.1 and 192.168.1.254 while($first[2] < $last[2]) { $first[3] = 1; #Resets 4th octet to 1 $first[2]++; #Adds 1 to 3rd octet of $first } } } sub trace { print "<h1>Tracing route, one moment...</h1>"; #Rejoin octets into $target for tracerouting... $target = join('.', $first[0],$first[1],$first[2],$first[3]); #Run traceroute on $target, only capture IP address to array @ip_addrs my @ip_addrs = map /\(([^)]*)\)/, qx( /usr/sbin/traceroute $target); #Cycle through @ip_addrs, print compy.gif for each hop foreach $element (@ip_addrs) { print "<center><img src=\"compy.gif\"><\/a><br>$element<br><br><\/cent +er>"; $|++; } #Re-splits $target for octet analysis @first = split(/\./,$target); }

In reply to Network topology mapping by mr_linux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.