#!/usr/local/bin/perl -wT #!/usr/bin/perl -wT ############################################################################### use strict; $ENV{PATH}='/bin:/usr/bin:/sbin:/usr/local/bin:/usr/local/etc:/usr/sbin:/usr/local/sbin';#For untainting my $t00=time(); ################### Testing ############################################## # For testing from command line you need to set some environment variables, # if you are user cottrell@pinger.slac.stanford.edu then you are using the tcsh shell # First set: # setenv REQUEST_URI /cgi-bin/traceroute.pl #For IPv4 # setenv REMOTE_ADDR 72.14.204.105; setenv SERVER_NAME www.slac.stanford.edu; setenv REMOTE_HOST www.google.com; setenv QUERY_STRING 'target=www.google.com&function=traceroute'; #For IPv6 # setenv REMOTE_ADDR 2a00:1450:8007::6a; setenv SERVER_NAME ui2-4.dir.garr.it # setenv QUERY_STRING 'target=ipv6.google.com'; setenv REMOTE_HOST ipv6.google.com # If you are NOT user cottrell or NOT on pinger.slac.stanford.edu then you are using the bash shell, # Then you will be using the bash shell. If you are using the bash shell then: # replace setenv with export, eg: # export REQUEST_URI /cgi-bin/traceroute.pl # export REMOTE_ADDR 72.14.204.105; export SERVER_NAME www.slac.stanford.edu; export REMOTE_HOST www.google.com; export QUERY_STRING 'target=www.google.com&function=traceroute'; #You will also need to include the -T option in the command line if you want to # use the perl -d debug facility, i.e. you need to use: # perl -d -T traceroute.pl #URL tests for IPv6 are: # Good IPv6 address # http://www3.slac.stanford.edu/cgi-bin/traceroute.pl?target=2001:da8:270:2018:f816:3eff:fef3:bd3&function=traceroute # http://net.its.hawaii.edu/cgi-bin/traceroute.pl?target=2001%3A4860%3A8005%3A%3A68&function=traceroute&ipv=6 # http://www.slac.stanford.edu/cgi-bin/traceroute.pl?target=ipv6.google.com&function=traceroute # Bad IP address # http://www3.slac.stanford.edu/cgi-bin/traceroute-new.pl?target=2001:da8:2019:b238:4521:5866:9abf&function=traceroute #Other hints: # To find the IPv6 address of a host use # #dig ipv6.google.com -t AAAA # REMOTE_HOST, REMOTE_ADDR are the name and IP address of the client/browser # SERVER_NAME is the name of the web server, # QUERY_STRING is the name or IP address of the host to be probed. ######################################################################### # Put out header right at start to ensure it precedes any errors or bug reports. # To enable line-buffered output (more interactive output), change the name # of this script to nph-traceroute.pl or use a Unix logical link. select(STDOUT); $| = 1; # Flush output after each print my $msg=""; if ($0 =~ /nph-/) { $msg="$ENV{SERVER_PROTOCOL} 200 OK\nServer: $ENV{SERVER_SOFTWARE}\n"; } #Get this out first so can get out error messages print $msg."Content-type: text/html\n\n"; my $version='8.0, 2/12/2021, Les Cottrell'; #Improved timeout and killing zombies. Fixed link for private IP address. $version='8.1, 10/31/2023, Les Cottrell'; ########################################################################## #Understand the local environment use Cwd; my $AF_INET=2; my $debug=0; #$debug=2; (my $progname = $0) =~ s'^.*/''; my $uid=scalar(getpwuid($<)); #Get fully qualified IP address of the local host use Net::Domain qw(hostname hostfqdn hostdomain); my $hostname = hostfqdn(); my $ipv="4";#set default used by gethostbyname6 to decide if to force IPv6 my $ipaddr=gethostbyname6($hostname); my $site="";#Allows us to special case SLAC's configuration if($hostname=~/\.slac\.stanford\.edu/) {$site="slac";} my $archname=$^O; use HTML::Entities;#Sanitize responses, see https://www.perl.com/pub/2002/02/20/css.html/ ###################### Get the form action field ######################### #$form allows one to use a different form action field, e.g. #REQUEST_URI is of the form: /cgi-bin/traceroute.pl?choice=yes my ($temp, $bin_dir); ($temp,$bin_dir,$temp)=split /\//,$ENV{'REQUEST_URI'}; my $form="