WebDeveloper.com �: Where Web Developers and Designers Learn How to Build Web Sites, Program in Java and JavaScript, and More!   
Web Developer Resource Directory WebDev Jobs
Animated GIFs
CSS
CSS Properties
Database
Design
Flash
HTML
HTML 4.01 Tags
JavaScript
.NET
PHP
Reference
Security
Site Management
Video
XML/RSS
WD Forums
 Client-Side
  Development

    HTML
    XML
    CSS
    Graphics
    JavaScript
    ASP
    Multimedia
    Web Video
    Accessibility
    Dreamweaver
    General
    Accessibility
    Dreamweaver
    Expression Web

    General

 Server-Side
  Development

    PHP
    Perl
    .NET
    Forum, Blog, Wiki & CMS
    SQL
    Java
    Others

 Site Management
    Domain Names
    Search Engines
    Website Reviews

 Web Development
  Business Issues

    Business Matters

 Etc.
    The Coffee Lounge
    Computer Issues
    Feedback




Network Mapping at a Glance, Part 5
Doing it visually with your own Perl script.

by Kent Cearley

After the graphic is converted to GD's internal format, GD routines can be applied to the image. Now you'll have to define any colors you need to use in GD by specifying their RGB value (which should be identifiable from within your graphics software package). In this case, all we need is red:

$RED = $image->colorAllocate(255,0,0);

Next, we need a GD routine to flood-fill the x,y coordinates for nodes that failed the ping. The following command fits the bill:

$image->fill($x,$y,$RED);

This command can go into a loop to flag all unreachable nodes as follows:

 open(RESULTS, "/usr/local/bin/fping -u @check 2>/dev/null |"); while() { # While any failing nodes… chop; take off extraneous  $xy = $hosts{$_}; # Lookup x,y coordinate ($x,$y) = split(/,/,$xy); # parse it into x and y $image->fill($x,$y,$red); # flag the node as down } close(RESULTS); 

By now, you've loaded each node and its x,y coordinates from the NODES.DAT file, loaded the network map's GIF, searched through each node testing for reachability, and updated the map accordingly by toggling the colors of any failed nodes to a bright red on the network map. The only remaining task is to return the updated image to the browser:

 $| = 1; print "Content-type: image/gif\n\n"; print $image->gif; 

The $| = 1; construction sets the output to unbuffered so the image doesn't get chopped up on its way back through the CGI. The Content-type tells the browser to expect to receive a GIF image. The $image->gif routine converts the image from the GD format back into GIF, and the binary stream is sent back to the browser. The actual network.gif file was never altered.

We've added a few cosmetic touches to our completed script, shown in Figure 3. We've also added code to print a date-time stamp indicating how recently the image was generated. This stamp uses GD routines to add text to the image on-the-fly.

[Move on to the last part of the article]


Web Developer® Site Feedback
Web Developer®
Copyright © 2000 internet.com Corporation. All rights reserved.

http://www.internet.com



HTML5 Development Center


Recent Articles