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 4
Doing it visually with your own Perl script.

by Kent Cearley

The <IMG> script

The script called by the <IMG> tag has to complete three tasks:

  1. Check the status of each node on the map.

  2. Indicate the status by filling the nodes with an appropriate color.

  3. Send the modified GIF back to the browser.
To check each node on the map, the script must parse the coordinate file created earlier and ping each coordinate's associated IP address. Parsing lines from a file into tokens is one of Perl's strengths; the script easily accomplishes this with the following snippet:

open(NODES,'nodes.dat');
while() {
  chop;
  ($xy, $ipaddr) = split(" "); # parse into two values
  push(@check,$ipaddr);        # add ip address to list
  $hosts{$ipaddr} = $xy;      # add both to lookup table
 }
close(NODES);

This code reads all the nodes from NODES.DAT into an associative array ($hosts), where the x,y coordinates can be checked by using their associated IP addresses. In addition, the IP addresses alone are added to a Perl list (@check), which can be passed in toto to the ping routine as follows:

open(RESULTS, "/usr/local/bin/fping -u @check 2>/dev/null |"); The line above opens a pipe to the fping command (see How to Install Fping and sends all the IP addresses that you want checked. Fping will return only the nodes that didn't respond to the pings, as set by the -u flag. These failing nodes can be read from the RESULTS handle, which returns them one per line. Using the associative array created earlier, the IP addresses returned from RESULTS act as keys for looking up the x,y coordinates. These coordinates are then used to fill the node's area on the map with a red alert. To change the color of the node, we'll need to modify the GIF on-the-fly with some routines from the GD library (see sidebar on "Using GD.pm").

To manipulate a GIF image, GD must first load and convert the GIF to an internal format. The following code fragment loads your network map:

open(GIF,"network.gif");
    $image->newFromGif GD::Image(GIF);

[Move on to the next 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