好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php如何获取域名IP地址代码函数 - php函数

php如何获取域名IP地址代码函数

先看如下代码,两个输出结果是一样的:

$dm  =  'HdhCmsTestphpfensi测试数据' ;  $ip  =  gethostbyname ( $dm );  echo   gethostbyaddr ( $ip );  echo   $ip ; 

关于gethostbyname语法:

string gethostbyname ( string $hostname )

返回由主机名指定的互联网主机的ipv4地址

returns the ipv4 address of the internet host specified by hostname

下面有个例这是最好的方法我已经提出,以解决任何主机名称到ip地址时,它的快速,可靠,已超时的支持,一个无效的地址,例如unicode字符串,返回后4?秒,而不是8调用gethostbyname?它只能与unix虽然,代码如下:

function  getaddrbyhost( $host ,  $timeout  = 3) {      $query  = `nslookup -timeout= $timeout  -retry=1  $host `;      if (preg_match( '/ address: (.*) /' ,  $query ,  $matches ))         return  trim( $matches [1]);      return   $host ;  } 

gethostbyaddr 是获取internet主机名对应一个特定的ip地址,代码如下:

string  gethostbyaddr  ( string  $ip_address  )  $hostname  =  gethostbyaddr ( $_server [ 'remote_addr' ]);  echo   $hostname ; 

查看更多关于php如何获取域名IP地址代码函数 - php函数的详细内容...

  阅读:45次