Free web development scripts for the webmasterDevelopment Scripts

 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 2 users online
 o Most users online: 67
 o Home
  o Perl
   o Miscellaneous
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o Advertise Here Make Money
 o Free Wedding Websites
 o OxyScripts
 o devnet
 o designplace
 o Open Source Design
 o Wedding Vendor Directory

CGI Traceroute, Ping, and wget (Rated 0)

Description:

You simply enter a host name, and select either 'Traceroute', 'Ping', or 'wget' and get the results.

Code starts here


#!/usr/bin/perl -Tw
use strict;
use CGI qw(:all delete_all escapeHTML);
$|++;

$ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/
+sbin";

my %progs = (
'Traceroute' => 'traceroute',
'Ping' => 'ping -c 15',
'wget' => 'wget -q -O -'
);

my $cache = get_cache_handle();

if (my $session = param('session')) {
my $data = $cache->get($session);
unless ($data and ref $data eq "ARRAY") {
show_form();
}
print header(),
start_html(
-title => 'Results',
($data->[0] ? () : (-head => ["<meta http-equiv=refresh content=
+5>"]))
),
h1('Results'),
pre( escapeHTML($data->[1]) );
print p( em('... continuing ...')) unless $data->[0];
print end_html();
exit 0;
} elsif (my $host = param('host')) {
($host) = $host =~ /^([a-zA-Z0-9.\-]{1,100})\z/ ?
$1 : show_form();

my $session = get_session_id();
$cache->set($session, [0, ""]);

if (my $pid = fork) {
delete_all();
param('session', $session);
print redirect(self_url());
} elsif (defined $pid) {
close STDOUT; close STDERR;
my ($prog) = grep { param($_) } keys %progs;
show_form() unless $prog;
open STDOUT, "$progs{$prog} $host |";
my $buf;
while (<STDOUT>) {
$buf .= $_;
$cache->set($session, [0, $buf]);
}
$cache->set($session, [1, $buf]);
exit 0;
} else {
die "Cannot fork: $!";
}
} else {
show_form();
}

sub show_form {
print header(),
start_html('Select Tool'),
h1('Enter Host and Select Tool'),
start_form(),
textfield('host'), ' ',
submit('Traceroute'), ' ',
submit('Ping'), ' ',
submit('wget'),
end_form(),
end_html();
exit 0;
}

sub get_cache_handle {
require Cache::FileCache;

Cache::FileCache->new({
namespace => 'tools',
username => 'nobody',
default_expires_in => '10 minutes',
auto_purge_interval => '2 hours',
});
}

sub get_session_id {
require Digest::MD5;

Digest::MD5::md5_hex(
Digest::MD5::md5_hex(time().{}.rand().$$)
);
}


Submitted by Devscripts on 13-02-2003 20:26


Rate This Script

User Contributed Comments

Registered Members login
© Copyright 2003 - Devscripts.net