Click to See Complete Forum and Search --> : Problem about using Ping and Traceroute with Perl


lasse
01-28-2003, 01:05 PM
I got this kind of question who can help me to solve it, thanks!

A link to a CGI script that would ping(if the firewall allowed it):
i) a machine at the university closest to your home.
ii) one of hte machines at a commercial organisation in the same town,
iii)and the router at which the two different routes diverge i.e. the last common router on the paths to machines(i) and (ii).

I don't know how to use PERL to add ping and traceroute run in the script. Now I just know to use the PERL print out the "hello world" :p

So need some one to give the souce code. Thank you very much.

perl at /usr/local/bin/perl
ping and traceroute at /usr/sbin/ping and /usr/sbin/traceroute

Paco Zarabozo
02-07-2003, 05:43 PM
To run any command line in a perl script, you only need to do this:

_________________________
#!perl
$| = 1;
print "Content-type:text/html\n\n";

# This will send a command line and will
# store the answer in the given array:

@ping = `ping yahoo.com`;

# Now, to actually print the answer:

foreach $i (@ping) {
print "$i\n<br>";
}

# You can continue with other commands:

@tracert = `tracert yahoo.com`;

# Again, you can print (or do whatever with) the answer:

foreach $i (@tracert) {
# Here you can print or analize each line of the answer
print "$i\n<br>";
}
_____________________________________

Now, you need to know what commands you want to run and what are you going to do with the answer. Also, to ping a certain university, you need to have a list of domains or IPs; the script cannot just know that. Also, the script cannot know which one is the nearest. You need to manage that with more code. If you need to learn, i recommend you http://www.cgi101.com (go to the online class and print the first 6 free chapters). If you like the method, then you can buy the actual book.

Paco.