internet.com

Go to WebDeveloper Home


hm-v6-139x61.gif

Database Journal: The Knowledge Center for Database Professionals

find a web host with:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
jobs

Get FREE Development Info via your Email!

The Webdeveloper channel
FlashKit
GIF.com
HiermenusCentral
webdeveloper Jobs
Java Boutique
JavaScript.com
JavaScript Source
ScriptSearch
StreamingMedia World
WDJ
WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com

internet.com
Internet News
Internet Investing
Internet Technology
Windows Internet Tech.
Linux/Open Source
Web Developer
ECommerce/Marketing
ISP Resources
ASP Resources
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers

internet.commerce
Be a Commerce Partner










Library

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/

Web Developer® Home Over a dozen topics in detail Live Chat Downloads Book and Product Reviews Threaded Discussions How-To/Articles/Links Developer Daily News Subscribe Search Corporate Information Advertise Events Publications internet.com Home