Peering Email
peering [ at ] ukgrid.net
NOC Email
noc [ at ] ukgrid.net
NOC Phone
+44 (0)845 260 4743
###############################################################################
# #
# PHP Net Tools #
# Copyright (C) 2006 Eric Robertson #
# h4rdc0d3@gmail.com #
# #
# ------- #
# #
# PHP Net Tools is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, please visit http://www.gnu.org #
# #
# ------- #
# #
# You are permitted to edit and redistrubute this code as you wish, #
# as long as you give credit where due and include a copy of the GPL. #
# #
# PHP Net Tools includes the following functional and configurable features: #
# Resolve host/reverse DNS lookup, find the country in which the target #
# host is located, ip whois, domain whois, ns lookup, dig, http request, #
# ping, traceroute, tracepath, portscan, nmap, and info logging. #
# #
# Please see the help option ([?]) for more information on each function. #
# #
# ------- #
# #
# last revision: 10.06.2006 (v2.8.2) #
# see changelog.txt #
# #
###############################################################################
// Set script version number
$version = '2.8.2';
// Log information of anyone visiting the site? (default = FALSE)
$enable_log_user = FALSE;
// Declare some globals
global $ip, $host_name, $host_ip, $url_parts;
// Shorten the variable names from submitted form elements - also initializes the variables for security
//
// NEW METHOD:
// This method is faster as it dynamically creates variables only for the necessary POST elements.
// It is also neater and uses much less code. The only downfall is that it is less intuitive to read.
//
// (for info on how "variable variables" work, see http://www.php.net/manual/en/language.variables.variable.php)
//
$post_keys = array_keys($_POST);
for ($i = 0; $i < count($post_keys); $i++)
{
$$post_keys[$i] = $_POST[$post_keys[$i]];
}
// Function to split a URL into its components
function split_url($host)
{
global $url_parts;
$url_parts = parse_url($host);
// If no port specified, default to port 80
if (!isset($url_parts['port'])) {
$url_parts['port'] = 80; }
// If no path specified, default to "/"
if (!isset($url_parts['path'])) {
$url_parts['path'] = '/'; }
}
// Function to find the ip address of the user
function get_ip()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; }
elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP']; }
else {
$ip = $_SERVER['REMOTE_ADDR']; }
return $ip;
}
// Function to print the Resolve Host/Reverse Lookup option results
function resolve($host)
{
global $host_name, $host_ip;
// 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;
}
echo "$host resolved to ";
if ($host == $host_name) {
echo "$host_ip
"; }
else {
echo "$host_name
"; }
}
// 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.ripe.net" requires a "+" flag to get all the details
if ($whois_ip_server == 'whois.ripe.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 .= ''; 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:'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
'; 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 $whois_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); $whois_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') { $whois_host .= '/e'; } // Set a variable containing the command to be sent to the system $command = "whois -h $whois_domain_server $whois_host"; // 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"); // Save the results as a variable and send to the parse_output() function $output = 'Whois (Domain) Results:'; echo 'Invalid character(s) in the Whois (IP) Server field.'; echo '
'; $output .= ''; parse_output($output); } else { echo 'Whois (Domain) Results:'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
'; 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:'; echo 'Invalid character(s) in the Whois (Domain) Server field.'; echo '
'; $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 necessary 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 .= '
"; $output .= ''; parse_output($output); } else { echo "Dig Results ($dig_class):'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
"; 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:'; echo 'Invalid characters in the Dig Server field.'; echo '
'; $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 .= '
'; $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 .= '
'; $output .= ''; parse_output($output); } // 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 $output = eregi_replace("([0-9]{1,3}(\.[0-9]{1,3}){3})", "\\0", $input); // Convert email addresses to links $output = eregi_replace($regex, "\\0", $output); // Print the results echo $output; } // Set the default value for certain variables if (!$host) { $host = 'Enter Host or IP'; } if (!$whois_ip_server) { $whois_ip_server = 'whois.ripe.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(); ?>'; $output .= nl2br(htmlentities(trim($fp))); $output .= '
peering [ at ] ukgrid.net
noc [ at ] ukgrid.net
+44 (0)845 260 4743