您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/11/5 2:03:49发布23次查看
先看如下代码,两个输出结果是一样的:
$dm = 'www.phpfensi.com'; 
$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;
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product