home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / php / PEAR / Net / DNS.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  14.5 KB  |  507 lines

  1. <?php
  2. /**
  3. * Class to provide IPv4 calculations
  4. *
  5. * Module written/ported by Eric Kilfoil <eric@ypass.net>
  6. *
  7. * This is the copyright notice from the PERL Net::DNS module:
  8. *
  9. * Copyright (c) 1997-2000 Michael Fuhr.  All rights reserved.  This
  10. * program is free software; you can redistribute it and/or modify it
  11. * under the same terms as Perl itself.
  12. *
  13. * The majority of this is _NOT_ my code.  I simply ported it from the
  14. * PERL Net::DNS module.
  15. *
  16. * The author of the Net::DNS module is Michael Fuhr <mike@fuhr.org>
  17. * http://www.fuhr.org/~mfuhr/perldns/
  18. *
  19. * Michael Fuhr has nothing to with the porting of this code to PHP.
  20. * Any questions directly related to this class library should be directed
  21. * to the maintainer.
  22. *
  23. *
  24. * PHP versions 4 and 5
  25. *
  26. * LICENSE: This source file is subject to version 3.01 of the PHP license
  27. * that is available through the world-wide-web at the following URI:
  28. * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
  29. * the PHP License and are unable to obtain it through the web, please
  30. * send a note to license@php.net so we can mail you a copy immediately.
  31. *
  32. * @category   Net
  33. * @package    Net_IPv4
  34. * @author     Eric Kilfoil <edk@ypass.net>
  35. * @author     Marco Kaiser <bate@php.net>
  36. * @author     Florian Anderiasch <fa@php.net>
  37. * @copyright  1997-2005 The PHP Group
  38. * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
  39. * @version    CVS: $Id: DNS.php,v 1.14 2006/10/25 17:52:44 bate Exp $
  40. * @link       http://pear.php.net/package/Net_DNS
  41. */
  42.  
  43. /* Include information {{{ */
  44.  
  45.     require_once("Net/DNS/Header.php");
  46.     require_once("Net/DNS/Question.php");
  47.     require_once("Net/DNS/Packet.php");
  48.     require_once("Net/DNS/Resolver.php");
  49.     require_once("Net/DNS/RR.php");
  50.  
  51. /* }}} */
  52. /* GLOBAL VARIABLE definitions {{{ */
  53.  
  54. // Used by the Net_DNS_Resolver object to generate an ID
  55.  
  56. $GLOBALS['_Net_DNS_packet_id'] = mt_rand(0, 65535);
  57.  
  58. /* }}} */
  59. /* Net_DNS object definition (incomplete) {{{ */
  60. /**
  61.  * Initializes a resolver object
  62.  *
  63.  * Net_DNS allows you to query a nameserver for DNS  lookups.  It bypasses the
  64.  * system resolver library  entirely, which allows you to query any nameserver,
  65.  * set your own values for retries, timeouts, recursion,  etc.
  66.  *
  67.  * @author Eric Kilfoil <eric@ypass.net>
  68.  * @package Net_DNS
  69.  * @version 0.01alpha
  70.  */
  71. class Net_DNS
  72. {
  73.     /* class variable definitions {{{ */
  74.     /**
  75.      * A default resolver object created on instantiation
  76.      *
  77.      * @var Net_DNS_Resolver object
  78.      */
  79.     var $resolver;
  80.     var $VERSION = '1.00b2'; // This should probably be a define :(
  81.     var $PACKETSZ = 512;
  82.     var $HFIXEDSZ = 12;
  83.     var $QFIXEDSZ = 4;
  84.     var $RRFIXEDSZ = 10;
  85.     var $INT32SZ = 4;
  86.     var $INT16SZ = 2;
  87.     /* }}} */
  88.     /* class constructor - Net_DNS() {{{ */
  89.  
  90.     /**
  91.      * Initializes a resolver object
  92.      *
  93.      * @see Net_DNS_Resolver
  94.      * @param array $defaults
  95.      * @return Net_DNS
  96.      */
  97.     function Net_DNS($defaults = array())
  98.     {
  99.         $this->resolver = new Net_DNS_Resolver($defaults);
  100.     }
  101.     /* }}} */
  102.     /* Net_DNS::opcodesbyname() {{{ */
  103.     /**
  104.      * Translates opcode names to integers
  105.      *
  106.      * Translates the name of a DNS OPCODE into it's assigned  number
  107.      * listed in RFC1035, RFC1996, or RFC2136. Valid  OPCODES are:
  108.      * <ul>
  109.      *   <li>QUERY
  110.      *   <li>IQUERY
  111.      *   <li>STATUS
  112.      *   <li>NS_NOTIFY_OP
  113.      *   <li>UPDATE
  114.      * <ul>
  115.      *
  116.      * @param   string  $opcode A DNS Packet OPCODE name
  117.      * @return  integer The integer value of an OPCODE
  118.      * @see     Net_DNS::opcodesbyval()
  119.      */
  120.     function opcodesbyname($opcode)
  121.     {
  122.         $op = array(
  123.                 'QUERY'        => 0,   // RFC 1035
  124.                 'IQUERY'       => 1,   // RFC 1035
  125.                 'STATUS'       => 2,   // RFC 1035
  126.                 'NS_NOTIFY_OP' => 4,   // RFC 1996
  127.                 'UPDATE'       => 5,   // RFC 2136
  128.                 );
  129.         if (! strlen($op[$opcode])) {
  130.             $op[$opcode] = null;
  131.         }
  132.         return $op[$opcode];
  133.     }
  134.  
  135.     /* }}} */
  136.     /* Net_DNS::opcodesbyval() {{{*/
  137.     /**
  138.      * Translates opcode integers into names
  139.      *
  140.      * Translates the integer value of an opcode into it's name
  141.      *
  142.      * @param   integer $opcodeval  A DNS packet opcode integer
  143.      * @return  string  The name of the OPCODE
  144.      * @see     Net_DNS::opcodesbyname()
  145.      */
  146.     function opcodesbyval($opcodeval)
  147.     {
  148.         $opval = array(
  149.                 0 => 'QUERY',
  150.                 1 => 'IQUERY',
  151.                 2 => 'STATUS',
  152.                 4 => 'NS_NOTIFY_OP',
  153.                 5 => 'UPDATE',
  154.                 );
  155.         if (! strlen($opval[$opcodeval])) {
  156.             $opval[$opcodeval] = null;
  157.         }
  158.         return $opval[$opcodeval];
  159.     }
  160.  
  161.     /*}}}*/
  162.     /* Net_DNS::rcodesbyname() {{{*/
  163.     /**
  164.      * Translates rcode names to integers
  165.      *
  166.      * Translates the name of a DNS RCODE (result code) into it's assigned number.
  167.      * <ul>
  168.      *   <li>NOERROR
  169.      *   <li>FORMERR
  170.      *   <li>SERVFAIL
  171.      *   <li>NXDOMAIN
  172.      *   <li>NOTIMP
  173.      *   <li>REFUSED
  174.      *   <li>YXDOMAIN
  175.      *   <li>YXRRSET
  176.      *   <li>NXRRSET
  177.      *   <li>NOTAUTH
  178.      *   <li>NOTZONE
  179.      * <ul>
  180.      *
  181.      * @param   string  $rcode  A DNS Packet RCODE name
  182.      * @return  integer The integer value of an RCODE
  183.      * @see     Net_DNS::rcodesbyval()
  184.      */
  185.     function rcodesbyname($rcode)
  186.     {
  187.         $rc = array(
  188.                 'NOERROR'   => 0,   // RFC 1035
  189.                 'FORMERR'   => 1,   // RFC 1035
  190.                 'SERVFAIL'  => 2,   // RFC 1035
  191.                 'NXDOMAIN'  => 3,   // RFC 1035
  192.                 'NOTIMP'    => 4,   // RFC 1035
  193.                 'REFUSED'   => 5,   // RFC 1035
  194.                 'YXDOMAIN'  => 6,   // RFC 2136
  195.                 'YXRRSET'   => 7,   // RFC 2136
  196.                 'NXRRSET'   => 8,   // RFC 2136
  197.                 'NOTAUTH'   => 9,   // RFC 2136
  198.                 'NOTZONE'   => 10,    // RFC 2136
  199.                 );
  200.         if (! strlen($rc[$rcode])) {
  201.             $rc[$rcode] = null;
  202.         }
  203.         return $rc[$rcode];
  204.     }
  205.  
  206.     /*}}}*/
  207.     /* Net_DNS::rcodesbyval() {{{*/
  208.     /**
  209.      * Translates rcode integers into names
  210.      *
  211.      * Translates the integer value of an rcode into it's name
  212.      *
  213.      * @param   integer $rcodeval   A DNS packet rcode integer
  214.      * @return  string  The name of the RCODE
  215.      * @see     Net_DNS::rcodesbyname()
  216.      */
  217.     function rcodesbyval($rcodeval)
  218.     {
  219.         $rc = array(
  220.                 0 => 'NOERROR',
  221.                 1 => 'FORMERR',
  222.                 2 => 'SERVFAIL',
  223.                 3 => 'NXDOMAIN',
  224.                 4 => 'NOTIMP',
  225.                 5 => 'REFUSED',
  226.                 6 => 'YXDOMAIN',
  227.                 7 => 'YXRRSET',
  228.                 8 => 'NXRRSET',
  229.                 9 => 'NOTAUTH',
  230.                 10 => 'NOTZONE',
  231.                 );
  232.         if (! strlen($rc[$rcodeval])) {
  233.             $rc[$rcodeval] = null;
  234.         }
  235.         return $rc[$rcodeval];
  236.     }
  237.  
  238.     /*}}}*/
  239.     /* Net_DNS::typesbyname() {{{*/
  240.     /**
  241.      * Translates RR type names into integers
  242.      *
  243.      * Translates a Resource Record from it's name to it's  integer value.
  244.      * Valid resource record types are:
  245.      *
  246.      * <ul>
  247.      *   <li>A
  248.      *   <li>NS
  249.      *   <li>MD
  250.      *   <li>MF
  251.      *   <li>CNAME
  252.      *   <li>SOA
  253.      *   <li>MB
  254.      *   <li>MG
  255.      *   <li>MR
  256.      *   <li>NULL
  257.      *   <li>WKS
  258.      *   <li>PTR
  259.      *   <li>HINFO
  260.      *   <li>MINFO
  261.      *   <li>MX
  262.      *   <li>TXT
  263.      *   <li>RP
  264.      *   <li>AFSDB
  265.      *   <li>X25
  266.      *   <li>ISDN
  267.      *   <li>RT
  268.      *   <li>NSAP
  269.      *   <li>NSAP_PTR
  270.      *   <li>SIG
  271.      *   <li>KEY
  272.      *   <li>PX
  273.      *   <li>GPOS
  274.      *   <li>AAAA
  275.      *   <li>LOC
  276.      *   <li>NXT
  277.      *   <li>EID
  278.      *   <li>NIMLOC
  279.      *   <li>SRV
  280.      *   <li>ATMA
  281.      *   <li>NAPTR
  282.      *   <li>TSIG
  283.      *   <li>UINFO
  284.      *   <li>UID
  285.      *   <li>GID
  286.      *   <li>UNSPEC
  287.      *   <li>IXFR
  288.      *   <li>AXFR
  289.      *   <li>MAILB
  290.      *   <li>MAILA
  291.      *   <li>ANY
  292.      * <ul>
  293.      *
  294.      * @param   string  $rrtype A DNS packet RR type name
  295.      * @return  integer The integer value of an RR type
  296.      * @see     Net_DNS::typesbyval()
  297.      */
  298.     function typesbyname($rrtype)
  299.     {
  300.         $rc = array(
  301.                 'A'             => 1,
  302.                 'NS'            => 2,
  303.                 'MD'            => 3,
  304.                 'MF'            => 4,
  305.                 'CNAME'         => 5,
  306.                 'SOA'           => 6,
  307.                 'MB'            => 7,
  308.                 'MG'            => 8,
  309.                 'MR'            => 9,
  310.                 'NULL'          => 10,
  311.                 'WKS'           => 11,
  312.                 'PTR'           => 12,
  313.                 'HINFO'         => 13,
  314.                 'MINFO'         => 14,
  315.                 'MX'            => 15,
  316.                 'TXT'           => 16,
  317.                 'RP'            => 17,
  318.                 'AFSDB'         => 18,
  319.                 'X25'           => 19,
  320.                 'ISDN'          => 20,
  321.                 'RT'            => 21,
  322.                 'NSAP'          => 22,
  323.                 'NSAP_PTR'      => 23,
  324.                 'SIG'           => 24,
  325.                 'KEY'           => 25,
  326.                 'PX'            => 26,
  327.                 'GPOS'          => 27,
  328.                 'AAAA'          => 28,
  329.                 'LOC'           => 29,
  330.                 'NXT'           => 30,
  331.                 'EID'           => 31,
  332.                 'NIMLOC'        => 32,
  333.                 'SRV'           => 33,
  334.                 'ATMA'          => 34,
  335.                 'NAPTR'         => 35,
  336.                 'UINFO'         => 100,
  337.                 'UID'           => 101,
  338.                 'GID'           => 102,
  339.                 'UNSPEC'        => 103,
  340.                 'TSIG'          => 250,
  341.                 'IXFR'          => 251,
  342.                 'AXFR'          => 252,
  343.                 'MAILB'         => 253,
  344.                 'MAILA'         => 254,
  345.                 'ANY'           => 255,
  346.                 );
  347.         if (empty($rc[$rrtype])) {
  348.             $rc[$rrtype] = null;
  349.         }
  350.         return $rc[$rrtype];
  351.     }
  352.  
  353.     /*}}}*/
  354.     /* Net_DNS::typesbyval() {{{*/
  355.     /**
  356.      * Translates RR type integers into names
  357.      *
  358.      * Translates the integer value of an RR type into it's name
  359.      *
  360.      * @param   integer $rrtypeval  A DNS packet RR type integer
  361.      * @return  string  The name of the RR type
  362.      * @see     Net_DNS::typesbyname()
  363.      */
  364.     function typesbyval($rrtypeval)
  365.     {
  366.         $rc = array(
  367.                 1 => 'A',
  368.                 2 => 'NS',
  369.                 3 => 'MD',
  370.                 4 => 'MF',
  371.                 5 => 'CNAME',
  372.                 6 => 'SOA',
  373.                 7 => 'MB',
  374.                 8 => 'MG',
  375.                 9 => 'MR',
  376.                 10 => 'NULL',
  377.                 11 => 'WKS',
  378.                 12 => 'PTR',
  379.                 13 => 'HINFO',
  380.                 14 => 'MINFO',
  381.                 15 => 'MX',
  382.                 16 => 'TXT',
  383.                 17 => 'RP',
  384.                 18 => 'AFSDB',
  385.                 19 => 'X25',
  386.                 20 => 'ISDN',
  387.                 21 => 'RT',
  388.                 22 => 'NSAP',
  389.                 23 => 'NSAP_PTR',
  390.                 24 => 'SIG',
  391.                 25 => 'KEY',
  392.                 26 => 'PX',
  393.                 27 => 'GPOS',
  394.                 28 => 'AAAA',
  395.                 29 => 'LOC',
  396.                 30 => 'NXT',
  397.                 31 => 'EID',
  398.                 32 => 'NIMLOC',
  399.                 33 => 'SRV',
  400.                 34 => 'ATMA',
  401.                 35 => 'NAPTR',
  402.                 100 => 'UINFO',
  403.                 101 => 'UID',
  404.                 102 => 'GID',
  405.                 103 => 'UNSPEC',
  406.                 250 => 'TSIG',
  407.                 251 => 'IXFR',
  408.                 252 => 'AXFR',
  409.                 253 => 'MAILB',
  410.                 254 => 'MAILA',
  411.                 255 => 'ANY',
  412.                 );
  413.         $rrtypeval = preg_replace(array('/\s*/',' /^0*/'), '', $rrtypeval);
  414.         if (empty($rc[$rrtypeval])) {
  415.             $rc[$rrtypeval] = null;
  416.         }
  417.         return $rc[$rrtypeval];
  418.     }
  419.  
  420.     /*}}}*/
  421.     /* Net_DNS::classesbyname() {{{*/
  422.     /**
  423.      * translates a DNS class from it's name to it's  integer value. Valid
  424.      * class names are:
  425.      * <ul>
  426.      *   <li>IN
  427.      *   <li>CH
  428.      *   <li>HS
  429.      *   <li>NONE
  430.      *   <li>ANY
  431.      * </ul>
  432.      *
  433.      * @param   string  $class  A DNS packet class type
  434.      * @return  integer The integer value of an class type
  435.      * @see     Net_DNS::classesbyval()
  436.      */
  437.     function classesbyname($class)
  438.     {
  439.         $rc = array(
  440.                 'IN'   => 1,   // RFC 1035
  441.                 'CH'   => 3,   // RFC 1035
  442.                 'HS'   => 4,   // RFC 1035
  443.                 'NONE' => 254, // RFC 2136
  444.                 'ANY'  => 255  // RFC 1035
  445.                 );
  446.         if (!isset($rc[$class])) {
  447.             $rc[$class] = null;
  448.         }
  449.         return $rc[$class];
  450.     }
  451.  
  452.     /*}}}*/
  453.     /* Net_DNS::classesbyval() {{{*/
  454.     /**
  455.      * Translates RR class integers into names
  456.      *
  457.      * Translates the integer value of an RR class into it's name
  458.      *
  459.      * @param   integer $classval   A DNS packet RR class integer
  460.      * @return  string  The name of the RR class
  461.      * @see     Net_DNS::classesbyname()
  462.      */
  463.     function classesbyval($classval)
  464.     {
  465.         $rc = array(
  466.                 1 => 'IN',
  467.                 3 => 'CH',
  468.                 4 => 'HS',
  469.                 254 => 'NONE',
  470.                 255 => 'ANY'
  471.                 );
  472.         $classval = preg_replace(array('/\s*/',' /^0*/'), '', $classval);
  473.         if (empty($rc[$classval])) {
  474.             $rc[$classval] = null;
  475.         }
  476.         return $rc[$classval];
  477.     }
  478.  
  479.     /*}}}*/
  480.     /* not completed - Net_DNS::mx() {{{*/
  481.     /*}}}*/
  482.     /* not completed - Net_DNS::yxrrset() {{{*/
  483.     /*}}}*/
  484.     /* not completed - Net_DNS::nxrrset() {{{*/
  485.     /*}}}*/
  486.     /* not completed - Net_DNS::yxdomain() {{{*/
  487.     /*}}}*/
  488.     /* not completed - Net_DNS::nxdomain() {{{*/
  489.     /*}}}*/
  490.     /* not completed - Net_DNS::rr_add() {{{*/
  491.     /*}}}*/
  492.     /* not completed - Net_DNS::rr_del() {{{*/
  493.     /*}}}*/
  494. }
  495. /* }}} */
  496. /* VIM Settings {{{
  497.  * Local variables:
  498.  * tab-width: 4
  499.  * c-basic-offset: 4
  500.  * soft-stop-width: 4
  501.  * c indent on
  502.  * End:
  503.  * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  504.  * vim<600: sw=4 ts=4
  505.  * }}} */
  506. ?>
  507.