Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tracerouting

Status
Not open for further replies.

jvdboom

Programmer
Aug 18, 2002
93
BE
To view the route from a webserver(for windows) to a site I made this script.I uses the dos command tracert, however it's a very slow(but that's normal for tracert).but the script only shows the information at the end of the the tracert session (if i execute the script without a webserver I see the information when it comes avaible.
Is it possible to write to the browser when the program is still running?
#!c:\perl\bin\perl.exe

$test = $ENV{QUERY_STRING};

if ($test =~ /^url=(h?t?t?p?:?\/?\/?\w*\.?\w*\.?\w*\.\w*\/?~?\w*)/ ) {


open(TRACE, "tracert $1 |");
print "Content-type: text/html\n\n";
while(<TRACE>) {print $_ . &quot;<br>&quot;;}
close(TRACE);
} else {
print &quot;Content-type: text/html\n\n<h1>Error!!!</h1>&quot; }
 
Add to your program the following line:
Code:
$| = 1; #turn flush on

This line should be at the very beginning of your program and will output the information from your script as it occurs instead of waiting for the completion of the script.
 
I got this to work in IE6 (but not opera) running off an Apache server. I don't think the magic header is very portable.
Code:
#!/usr/bin/perl

$| = 1;

print &quot;Content-type: multipart/mixed\n\n&quot;;

my $url = $ENV{QUERY_STRING};

print &quot;<html><body>\n&quot;;

# I have traceroute instead of tracert on my box
open(TRACE, &quot;traceroute $url 2>&1 |&quot;);
print $_ . &quot;<br>&quot; while <TRACE>;
close(TRACE);

print &quot;</body></html>\n&quot;;

exit;

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top