-
Notifications
You must be signed in to change notification settings - Fork 24
/
traceroute.cgi
executable file
·95 lines (77 loc) · 2.18 KB
/
traceroute.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl -w -T
#
# (c) Copyright 2001, Michael C. Toren <[email protected]>
#
# mct, Fri Jul 20 15:33:21 EDT 2001
# mct, Wed Aug 1 14:39:36 EDT 2001
# mct, Tue Mar 30 08:45:08 EST 2004
#
use CGI;
use strict;
my ($q, $me, $bin, $host, $type, $validhost, $validtype, @command);
$q = new CGI;
$me = (split /\?/, $q->self_url)[0] || "";
$host = $q->param("h") || ($q->keywords)[0] || "";
$type = $q->param("t") || "u";
$ENV{PATH} = "/usr/sbin";
$validhost = ($host =~ /^[a-z0-9_\.]+$/i) ? $host : "";
$validtype = ($type =~ /^[tiu]$/) ? $type : "u";
$bin = {
t => { string => "TCP", command => [ qw(/usr/bin/tcptraceroute ) ] },
u => { string => "UDP", command => [ qw(/usr/sbin/traceroute ) ] },
i => { string => "ICMP", command => [ qw(/usr/sbin/traceroute -I ) ] }
};
print $q->header("text/html"), <<" !";
<html>
<head>
<title>Traceroute CGI Gateway</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
vlink="#551A8B" alink="#0000FF">
<center>
<br>
<center>
<font size="7"><tt><b>traceroute CGI gateway</b></tt></font>
</center>
<br>
<form method=get action=$me>
Host: <input type=text name=h
value=${\( $validhost ? $validhost : $ENV{REMOTE_ADDR} )}>
UDP <input type=radio name=t
value=u ${\( $validtype eq "u" ? "checked" : "" )}>
ICMP <input type=radio name=t
value=i ${\( $validtype eq "i" ? "checked" : "" )}>
<a href=http://michael.toren.net/code/tcptraceroute>TCP</a>
<input type=radio name=t
value=t ${\( $validtype eq "t" ? "checked" : "" )}>
<input type=submit value=Go>
</form>
</center>
!
exit unless ($host);
unless ($validhost)
{
print <<" !";
<blockquote>
<font color=red>ERROR:</font> Invalid hostname!
</blockquote>
</body>
</html>
!
exit;
}
$| = 1;
close STDERR;
open STDERR, ">&STDOUT";
@command = (@{ $bin->{$validtype}->{command} }, $validhost);
print "<br><hr width=50%><br><br>\n";
print "% <b>", join(" ", @command), "</b>\n<pre>\n";
# $bin->{$validtype}->{string}, " packets.\n<pre>\n";
system { $command[0] } @command;
print <<" !";
</pre>
</body>
</html>
!
exit;