download this file: class.network.php view text/plain: class.network.php file encoding: UTF-8 [goback]
<?php
##
## this file name is 'class.network.php'
##
## network object
##
## [author]
##  - Chilbong Kim, <san2(at)linuxchannel.net>
##  - http://linuxchannel.net/
##
## [changes]
##  - 2004.03.23 : add dns::get_rr()
##  - 2004.02.29 : new build
##
## [references]
##
## [usage]
##
## [example]
##
class network
{
  function &
inet_aton($ipaddr)
  {
    return 
sprintf('%u',ip2long($ipaddr));
  }

  function &
inet_ntoa($base)
  {
    return 
long2ip($base);
  }

  function &
inet_ntob($base)
  {
    return 
sprintf('%032b',$base);
  }

  function &
inet_bton($bits)
  {
    return 
bindec($bits);
  }

  function &
inet_atob($ipaddr)
  {
    return 
sprintf('%032b',ip2long($ipaddr));
  }

  function &
inet_btoa($bits)
  {
    return 
long2ip(sprintf('%u',$bits));
  }

  function &
is_subnet($some)
  {
    
$some trim($some);

    if(
preg_match('/^[\d]+\.[\d]+\.[\d]+\.[\d]+$/',$some))
    {
        
$some sprintf('%u',ip2long($some));
    }

    
$dec abs($some);
    
$bits decbin($dec);
    return (boolean) 
preg_match('/^[1]+[0]*$/',$bits);
  }
// end of class

class dns
{
  function &
get_rr($host$type='A'$authns=array(), $addtl=array())
  {
    
$rrd = array();
    
$dns = new net_dns_resolver;
    
$pks $dns->query($host,$type);
    
//_print_r($pks);

    
$ancount $pks->header->ancount;
    
$nscount $pks->header->nscount;
    
$arcount $pks->header->arcount;

    for(
$i=0$i<$ancount$i++)
    {
        
$rrd[] = get_object_vars($pks->answer[$i]);
    }

    for(
$i=0$i<$nscount$i++)
    {
        
$authns[] = get_object_vars($pks->authority[$i]);
    }

    for(
$i=0$i<$arcount$i++)
    {
        
$addtl[] = get_object_vars($pks->additional[$i]);
    }

    return 
$rrd;
  }
}

require_once 
'Net/DNS.php'// PEAR

?>