$host resolved to "; if ($host == $host_name) { echo "$host_ip

"; } else { echo "$host_name

"; } } // Function to find the country location of the machine host/ip function ip_to_country() { // Do a whois on the ip using "whois.arin.net" and store the results in $buffer $buffer = nl2br(whois_ip('whois.arin.net', '-1', 'FALSE')); // If the whois contains a line for a referral server, do a new whois using this server and store in $buffer if (eregi("ReferralServer:[[:space:]]*[a-z]*(whois://)*([a-z0-9-][\.a-z0-9-]{2,})[:]*([0-9]+)*", $buffer, $regs)) { $referral_host = $regs[2]; $buffer = nl2br(whois_ip($referral_host, $regs[3], 'FALSE')); } // If there is a line labeled "country", get its value and print it... if (eregi("country:[[:space:]]*([a-z]{2,})", $buffer, $regs)) { // Store the value of the "country" line from the buffer $country = $regs[1]; // Caching of the country list: If the file "list_file.txt" exists on the server, the country list was already cached, // so read it into the $list_file variable... if (file_exists('list_file.txt')) { $list_file = @file_get_contents('list_file.txt'); } // ...otherwise, download the country list and cache it on the server in the file "list_file.txt" else { // The ISO standards website provides a free text file listing every country and it's 2 character country code - // download this file and store it in the $list_file variable $list_file = @file_get_contents('http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1-semic.txt'); // Cache the country code list on the server $handle = fopen('list_file.txt', 'w'); @fwrite($handle, $list_file); fclose($handle); } // Convert the new line characters in the file contents to HTML line breaks and split it at each line into an array $list_file_br = nl2br($list_file); $list_rows = explode("
", $list_file_br); // Define an array to store the country info $country_list = array(); // Loop through each line in the file and save the 2 character country code and it's full name // in the $country_list array for ($i = 1; $i < count($list_rows); $i++) { $row = explode(";", $list_rows[$i]); $row_abbr = $row[1]; $row_name = ucwords(strtolower($row[0])); $country_list[$row_abbr] = $row_name; } // If the country in the whois buffer is in the country_list array, print its full name... if (array_key_exists($country, $country_list)) { echo "Location:  $country_list[$country] ($country)

"; } // ...otherwise, just print the 2 character country code listed in the whois buffer else { echo "Location:  $country

"; } } // ...or if there is no "country" line, print location unknown else { echo 'Location:  Unknown

'; } } // Function to perform a whois lookup on the machine's ip address function whois_ip($whois_ip_server, $whois_ip_port, $do_echo) { if (eregi("^[a-z0-9\:\.\-]+$", $whois_ip_server)) { global $host_ip; // The whois server "whois.arin.net" requires a "+" flag to get all the details if ($whois_ip_server == 'whois.arin.net') { $whois_ip_server .= ' +'; } // Set a variable containing the command to be sent to the system $command = "whois -h $whois_ip_server $host_ip"; // If we passed a specific port to this function to connect to, add the necessary info to the command if ($whois_ip_port > 0) { $command .= " -p $whois_ip_port"; } // Send the whois command to the system // Normally, the shell_exec function does not report STDERR messages. The "2>&1" option tells the system // to pipe STDERR to STDOUT so if there is an error, we can see it. $fp = shell_exec("$command 2>&1"); // If the $do_echo variable is set to "TRUE", send the results to the parse_output() function... if ($do_echo == 'TRUE') { $output = 'Whois (IP) Results:
'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
'; parse_output($output); } // ...otherwise, return the results in a variable (i.e. for the ip_to_country() function) else { return $fp; } } else { echo 'Whois (IP) Results:
'; echo 'Invalid character(s) in the Whois (IP) Server field.'; echo '
'; } } // Function to perform a whois lookup on a domain function whois_domain($host, $whois_domain_server) { if (eregi("^[a-z0-9\.\-]+$", $whois_domain_server)) { global $host_name, $host_ip; // Set the default value for a variable $who_host = $host; // Split the host into its domain levels $split_host = explode('.', $host_name); // If the host name contains "www", remove it if ($split_host[0] == 'www') { array_shift($split_host); $who_host = implode(".", $split_host); } // If searching a japanese whois server, use the "/e" switch to suppress japanese characters in the output if (substr($whois_domain_server, -3) == '.jp') { $who_host .= '/e'; } // Send the whois command to the system // Normally, the shell_exec function does not report STDERR messages. The "2>&1" option tells the system // to pipe STDERR to STDOUT so if there is an error, we can see it. $fp = shell_exec("whois -h $whois_domain_server $who_host 2>&1"); // Save the results as a variable and send to the parse_output() function $output = "Whois (Domain) Results:
"; $output .= nl2br(htmlentities(trim($fp))); $output .= "
"; parse_output($output); } else { echo 'Whois (Domain) Results:
'; echo 'Invalid character(s) in the Whois (Domain) Server field.'; echo '
'; } } // Function to perform an NS Lookup on a host/ip function nslookup($host) { // Set initial command to be run on the server $command = "nslookup $host -sil"; // Send the nslookup command to the system // Normally, the shell_exec function does not report STDERR messages. The "2>&1" option tells the system // to pipe STDERR to STDOUT so if there is an error, we can see it. $fp = shell_exec("$command 2>&1"); // Save the results as a variable and send to the parse_output() function $output = 'NS Lookup Results:
'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
'; parse_output($output); } // Function to perform a dig on a host/ip function dig($host, $dig_class, $dig_server) { if (eregi("^[a-z0-9\.\-]*$", $dig_server)) { // Set initial command to be run on the server $command = "dig -t $dig_class $host"; // If a dig server has been entered, add the correct info to the command if ($dig_server) { $command .= ' @' . $dig_server; } // Send the dig command to the system // Normally, the shell_exec function does not report STDERR messages. The "2>&1" option tells the system // to pipe STDERR to STDOUT so if there is an error, we can see it. $fp = shell_exec("$command 2>&1"); // Save the results as a variable and send to the parse_output() function $output = "Dig Results ($dig_class):
"; $output .= nl2br(htmlentities(trim($fp))); $output .= '
'; parse_output($output); } else { echo "Dig Results ($dig_class):
"; echo 'Invalid characters in the Dig Server field.'; echo '
'; } } // Function to perform a ping on a host/ip function ping($host, $ping_count) { // Set initial command to be run on the server $command = "ping -c $ping_count $host"; // Send the ping command to the system. // Normally, the shell_exec function does not report STDERR messages. The "2>&1" option tells the system // to pipe STDERR to STDOUT so if there is an error, we can see it. $fp = shell_exec("$command 2>&1"); // Save the results as a variable and send to the parse_output() function $output = 'Ping Results:
'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
'; parse_output($output); } // Function to perform a traceroute on a host/ip function traceroute($host) { // Set initial command to be run on the server $command = "traceroute $host"; // Send the traceroute command to the system. // Normally, the shell_exec function does not report STDERR messages. The "2>&1" option tells the system // to pipe STDERR to STDOUT so if there is an error, we can see it. $fp = shell_exec("$command 2>&1"); // Save the results as a variable and send to the parse_output() function $output = 'Traceroute Results:
'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
'; parse_output($output); } // Function to perform a tracepath on a host/ip function tracepath($host) { // Set initial command to be run on the server $command = "tracepath $host"; // Send the tracepath command to the system. // Normally, the shell_exec function does not report STDERR messages. The "2>&1" option tells the system // to pipe STDERR to STDOUT so if there is an error, we can see it. $fp = shell_exec("$command 2>&1"); // Save the results as a variable and send to the parse_output() function $output = 'Tracepath Results:
'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
'; parse_output($output); } // Function to perform a port scan on a host/ip function portscan($host, $ports, $scan_timeout) { if (eregi("^[0-9\,\-]+$", $ports)) { echo 'Portscan Results:
'; echo ""; // split the $ports variable into an array containing the port numbers to scan $port_array = explode(",", $ports); // Save the current time (for calculating how long the scan took) $start_time = time(); // Loop through the ports and check to see if they are open or not for ($i = 0; $i < count($port_array); $i++) { // If the current loop contains two sets of numbers with a dash separating them, // it is a range of ports, so create a new loop to scan and print out each one... if (eregi("([0-9]+)[-]{1}([0-9]+)", $port_array[$i], $regs)) { for ($x = $regs[1]; $x <= $regs[2]; $x++) { // Create a connection to the port $sock = @fsockopen($host, $x, $num, $error, $scan_timeout); // If we can connect to the port, set the port status to "open", // otherwise, set the port status to "closed" if ($sock) { $port_status = "open"; fclose($sock); } else { $port_status = 'closed'; } // Get the description of the port $port_name = getservbyport($x, 'tcp'); // Print the port status echo ""; // If the current port has a description/default use, print it if ($port_name != NULL) { echo ""; } echo ''; } } // ...otherwise, if the current loop contains just numbers, it is a single port, so scan it elseif (eregi("[0-9]+", $port_array[$i])) { // Create a connection to the port $sock = @fsockopen($host, $port_array[$i], $num, $error, $scan_timeout); // If we can connect to the port, set the port status to "open", // otherwise, set the port status to "closed" if ($sock) { $port_status = "open"; fclose($sock); } else { $port_status = 'closed'; } // Get the description of the port $port_name = getservbyport($port_array[$i], 'tcp'); // Print the port status echo ""; // If the current port has a description/default use, print it if ($port_name != NULL) { echo ""; } echo ''; } } // Save the current time again (for calculating how long the scan took) $end_time = time(); // Calculate the elapsed time during the port scan $time_diff = $end_time - $start_time; $mins = date('i', $time_diff); $secs = date('s', $time_diff); // If the the elapsed time during the port scan was less than a second, set it as taking 1 second // (it obviously has to take some amount of time) if (($mins == '00') && ($secs == '00')) { $secs = '01'; } // Print the elapsed time of the port scan echo ""; echo '
Port $x is $port_status.[$port_name]
Port $port_array[$i] is $port_status.[$port_name]

Portscan completed in $mins minutes and $secs seconds.
'; } else { echo 'Portscan Results:
'; echo 'Invalid characters in the Portscan field.'; echo '
'; } } // Function to perform an nmap on a host/ip function nmap($host, $nmap_options) { if (eregi("^[a-z0-9 @_:,-\.\*\/]+$", $nmap_options)) { // Set initial command to be run on the server $command = "nmap $nmap_options $host"; // Send the nmap command to the system. // Normally, the shell_exec function does not report STDERR messages. The "2>&1" option tells the system // to pipe STDERR to STDOUT so if there is an error, we can see it. $fp = shell_exec("$command 2>&1"); echo 'Nmap Results:
'; echo nl2br(htmlentities(trim($fp))); echo '
'; } else { echo 'Nmap Results:
'; echo 'Invalid characters in the Nmap field.'; echo '
'; } } // Function to parse the results of various commands to create shortcut links function parse_output($input) { // Create a regular expression to validate email addresses // (credit goes to "bobocop at bobocop dot cz" from "eregi" comments on php.net for this regular expression) $user = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; $domain = '([a-z]([-a-z0-9]*[a-z0-9]+)?)'; $regex = $user . '+(\.' . $user . '+)*@(' . $domain . '{1,63}\.)+' . $domain . '{2,63}'; // Convert IP addresses to links $parsed_ip = eregi_replace("([0-9]{1,3}(\.[0-9]{1,3}){3})", "\\0", $input); // Convert email addresses to links $parsed_email = eregi_replace($regex, "\\0", $parsed_ip); // Print the results $output = $parsed_email; echo $output; } // Set the default value for certain variables if ($host == "") { $host = 'Enter Host or IP'; } if ($whois_ip_server == "") { $whois_ip_server = 'whois.arin.net'; } if ($whois_domain_server == "") { $whois_domain_server = 'whois-servers.net'; } if ($ping_count == "") { $ping_count = '4'; } if ($scan_timeout == "") { $scan_timeout = '1'; } // Call the get_ip() function and store the results in $ip $ip = get_ip(); ?> PHP Net Tools
v
Host Information Host Connectivity
>Resolve Host / Reverse Lookup
>Get Country   [ ? ]
>Whois (IP)     [ ? ]
>Whois (Domain)    
>NS Lookup
>Dig       [ ? ]
>Ping  -  count:
>Traceroute
>Tracepath   [ ? ]
>Portscan     [ ? ]
        Timeout:   second(s)
>Nmap     [ ? ]
Host:     
$ip"; ?>





You must select at least one option to perform.'; exit; } // If there was no host entered, print an error if (($host == 'Enter Host or IP') || ($host == "")) { echo '

You must enter a valid Host or IP address.'; exit; } // If the value of $host begins with an alpha character, it must be a host name, so find its ip... if(eregi("^[a-z]", $host)) { $host_name = $host; $host_ip = gethostbyname($host); } // ...otherwise, it must be an ip address, so find its host name else { $host_name = gethostbyaddr($host); $host_ip = $host; } // If the option is set to log the user info, call the log_user() function if ($enable_log_user == TRUE) { log_user($host); } } // If an option is set, call its respective function if (isset($resolve)) { resolve($host); } if (isset($ip_to_country)) { ip_to_country(); } if (isset($whois_ip)) { whois_ip($whois_ip_server, '-1', 'TRUE'); } if (isset($whois_domain)) { whois_domain($host, $whois_domain_server); } if (isset($ns)) { nslookup($host); } if (isset($dig)) { dig($host, $dig_class, $dig_server); } if (isset($ping)) { ping($host, $ping_count); } if (isset($trace)) { traceroute($host); } if (isset($tracepath)) { tracepath($host); } if (isset($portscan)) { portscan($host, $ports, $scan_timeout); } if (isset($nmap)) { nmap($host, $nmap_options); } ?>