PHP Classes
elePHPant
Icontem

File: index_other.php

Recommend this page to a friend!
  Classes of Schroetter Christian  >  PHP Ping Traceroute and DNS  >  index_other.php  >  Download  
File: index_other.php
Role: Example script
Content type: text/plain
Description: Misc record example
Class: PHP Ping Traceroute and DNS
Send ping and traceroute ICMP request messages
Author: By
Last change:
Date: 4 years ago
Size: 3,647 bytes
 

Contents

Class file image Download
<?php
   
include_once('./geoip.class.php');
    include_once(
'./ping.class.php');

    function
PrintUsage($string = '')
    {
        if(
$string != '') {
            echo
$string . "\n\n";
        }

        echo
'php index_ping.php [addr] [-mx|-txt|-soa|-aaaa|-afsdb|-sshfp|-spf|-ns|-loc]' . "\n";
        echo
"\t" . '[addr] mandatory: The host (IP address or host name) to ping...' . "\n";
        echo
"\t" . '-mx: Request for Mail exchange record' . "\n";
        echo
"\t" . '-txt: Request for Text record' . "\n";
        echo
"\t" . '-soa: Request for Start of authority record' . "\n";
        echo
"\t" . '-aaaa: Request for IPv6 address record' . "\n";
        echo
"\t" . '-afsdb: Request for distributed service advertised record' . "\n";
        echo
"\t" . '-sshfp: Request for SSH Finger Print record' . "\n";
        echo
"\t" . '-spf: Request for Sender Policy Framework record' . "\n";
        echo
"\t" . '-ns: Request for Name server record' . "\n";
        echo
"\t" . '-loc: Request for Geographic location information record' . "\n";

        die(
"\n");
    }

    if(
$argc <= 1) {
       
PrintUsage('Paramètre(s) invalide(s)...');
        die(
"\n");
    }

   
$validsRequest = array();
   
$validsRequest[] = '-mx';
   
$validsRequest[] = '-txt';
   
$validsRequest[] = '-soa';
   
$validsRequest[] = '-aaaa';
   
$validsRequest[] = '-afsdb';
   
$validsRequest[] = '-sshfp';
   
$validsRequest[] = '-spf';
   
$validsRequest[] = '-ns';
   
$validsRequest[] = '-loc';

    if(
in_array($argv[2], $validsRequest)) {
        if(
$argc <= 2) {
           
PrintUsage('Addr for the quey is invalid.');
        }
    } else {
       
PrintUsage('"' . $argv[2] . '" is not a valid request.');
    }

   
$ping = new CPing();

   
$config = array();
   
$config['value'] = $argv[1];

    if(
$argv[2] == '-mx')
       
$config['type'] = DNS_CLASS_MX;
    else if(
$argv[2] == '-txt')
       
$config['type'] = DNS_CLASS_TXT;
    else if(
$argv[2] == '-soa')
       
$config['type'] = DNS_CLASS_SOA;
    else if(
$argv[2] == '-aaaa')
       
$config['type'] = DNS_CLASS_AAAA;
    else if(
$argv[2] == '-afsdb')
       
$config['type'] = DNS_CLASS_AFSDB;
    else if(
$argv[2] == '-sshfp')
       
$config['type'] = DNS_CLASS_SSHFP;
    else if(
$argv[2] == '-spf')
       
$config['type'] = DNS_CLASS_SPF;
    else if(
$argv[2] == '-ns')
       
$config['type'] = DNS_CLASS_NS;
    else if(
$argv[2] == '-loc')
       
$config['type'] = DNS_CLASS_LOC;

   
$output = $ping->DNSSolve($config);
    if(
$output === false)
    {
        echo
'Erreur de requête DNS...' . "\n";
    }
    else
    {
        foreach(
$output['records'] as $record)
        {
            if(
$record->Type == DNS_CLASS_A && $record->TTL > 0)
            {
                echo
'Host IP: ' . $record->rdData->ip . "\n";
               
$not_found = false;
            }
            else if(
$record->Type == DNS_CLASS_CNAME && $record->TTL > 0)
            {
                echo
'Host IP (alias): ' . $record->rdData->cname . "\n";
               
$not_found = false;
            }
            else if(
$record->Type == DNS_CLASS_PTR && $record->TTL > 0)
            {
                echo
'Host name: ' . $record->rdData->ptrdname . "\n";
               
$not_found = false;
            }
            else
            {
                echo
'Unknwon record: ' . "\n";
               
var_dump($record);
            }
        }

        foreach(
$output['authority'] as $authority)
        {
            if(
$authority->Type == DNS_CLASS_SOA)
            {
                echo
'General informations: ' . "\n";
                echo
"\t" . 'Original domain name: ' . $authority->rdData->mname . "\n";
                echo
"\t" . 'Responsible person\'s mail: ' . $authority->rdData->rname . "\n";
                echo
"\t" . 'Original version serial: ' . $authority->rdData->serial . "\n";
                echo
"\t" . 'Refresh information every: ' . (int)($authority->rdData->refresh / 60) . ',' . ($authority->rdData->refresh % 60) . 's' . "\n";
                echo
"\t" . 'Authoritative expire in: ' . (int)($authority->rdData->expire / 60) . ',' . ($authority->rdData->expire % 60) . 's' . "\n";

            }
            else
            {
                echo
'Unknwon authority: ' . "\n";
               
var_dump($authority);
            }
        }
    }

?>