PHP Classes

PHP Ping Traceroute and DNS: Send ping and traceroute ICMP request messages

Recommend this page to a friend!
  Info   View files Example   View files View files (22)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 470 This week: 1All time: 6,021 This week: 571Up
Version License PHP version Categories
ping-traceroute-dns 1.0Free for non-comm...5Networking, PHP 5, Geography
Description 

Author

This package can send ping and traceroute ICMP request messages.

It provides different classes for sending ICMP messages to computers with given IP addresses to implement the ping and traceroute tools in pure PHP.

There are also classes to perform network address queries to DNS servers, get the location of IP addresses using the GeoIP extension and get the operational system type.

Innovation Award
PHP Programming Innovation award nominee
October 2014
Number 5
Ping and traceroute are network tools often used to determine if a destination computer network is reachable from the local computer.

This class implements a pure PHP version of the ping and traceroute tools.

Manuel Lemos
Picture of Schroetter Christian
Name: Schroetter Christian <contact>
Classes: 5 packages by
Country: France France
Age: 46
All time rank: 180452 in France France
Week rank: 420 Up14 in France France Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Example

<?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";

?>


  Files folder image Files  
File Role Description
Files folder imagegeoip (3 files)
Files folder imageresources (1 file)
Plain text file dns_struct.php Class DNS Class definition
Plain text file echo_request.struct.php Class DNS Class definition
Accessible without login HTML file eng.kremlin.ru.html Data Traceroute sample
Plain text file geoip.class.php Class GeoIP wrapper
Accessible without login Plain text file icmp_define.php Conf. ICMP class definition
Plain text file icmp_header.struct.php Class Header ICMP class definition
Accessible without login Plain text file include.php Aux. Include file
Accessible without login Plain text file index_whois.php Example Whois example
Plain text file ip_header.struct.php Class IP header class definition
Plain text file os.class.php Class OS Class definition
Plain text file ping.class.php Class Ping (main) class definition
Plain text file ping_repply.struct.php Class Ping repply Class definition
Plain text file request.struct.php Class Generic request class definition
Plain text file trace_request.struct.php Class Trace request class definition
Accessible without login Plain text file index_dns.php Example DNS example
Accessible without login Plain text file index_other.php Example Misc record example
Accessible without login Plain text file index_ping.php Example Ping example
Accessible without login Plain text file index_traceroute.php Example Traceroute example

  Files folder image Files  /  geoip  
File Role Description
  Accessible without login Plain text file geoipregionvars.php Aux. GeoIP wrapper
  Accessible without login Plain text file geoip.inc.php Aux. GeoIP wrapper
  Accessible without login Plain text file geoipcity.inc.php Aux. GeoIP wrapper

  Files folder image Files  /  resources  
File Role Description
  Accessible without login Plain text file header.html Data Header for the traceroute output

 Version Control Unique User Downloads Download Rankings  
 0%
Total:470
This week:1
All time:6,021
This week:571Up