<?php
define('GMAP_KEY', your own gMap key here...);
$no_geoip = false;
if(file_exists('./geoip.class.php'))
include_once('./geoip.class.php');
else
$no_geoip = true;
include_once('./ping.class.php');
function PrintUsage($string = '')
{
if($string != '') {
echo $string . "\n\n";
}
echo 'php index_traceroute.php [addr] [-o] [-t:X]' . "\n";
echo "\t" . '[addr] mandatory: The host (IP address or host name) to ping...' . "\n";
echo "\t" . '[-o] optionnal: IF A GEOLOCALISATION THIRD PARTY LIBRARY IS INSTALLED: Output the Tracroute to view the paths in Google Map' . "\n";
echo "\t" . '[-ttl:X] optionnal: The TTL value' . "\n";
echo "\t" . '[-t:Y] optionnal: The timeout value (ms)' . "\n";
die("\n");
}
function TraceRoute($addr, $host, $ttl, $time)
{
echo $addr . ' - ' . $host . ' - ' . $ttl . ' - ' . $time . ' ms' . "\n";
}
if($argc <= 1) {
PrintUsage('Paramètre(s) invalide(s)...');
die("\n");
}
$ttl = 64;
$timeout = 1000;
for($i = 0 ; $i < $argc ; $i++)
{
if(strpos($argv[$i], '-t:') !== false)
$timeout = (int)substr($argv[$i], 3);
else if(strpos($argv[$i], '-ttl:') !== false)
$ttl = (int)substr($argv[$i], 5);
}
$ping = new CPing();
if($no_geoip === false)
{
// !!! WARNING !!! To use this features, you MUST download the "GeoIPCity.dat" file
// http://dev.maxmind.com/geoip/geoip2/downloadable/
// and put it in the "resources" directory, present near this script
$geoip = new CGeoIp('./resources/GeoIPCity.dat');
}
$straOut = $ping->TraceRoute($argv[1], $ttl, $timeout, 'TraceRoute');
if($straOut !== false)
{
if($straOut[count($straOut) - 1][0] === true)
echo "\t" . 'Host have been reached...' . "\n";
else
echo "\t" . 'An error occur while reaching the Host...' . "\n";
if(in_array('-o', $argv))
{
if($no_geoip === false)
$ping->OutputGMapRoute($argv[1], $straOut, GMAP_KEY, $geoip);
}
}
else
echo 'Erreur de TraceRoute...' . "\n";
?>
|