今天看到几个函数,可以根据ip地址 / 域名 获取对应的 域名 / ip 的函数。记录于此。 gethostbynamel($hostname) // 根据 域名 获取 IP,返回一个数组,比如baidu。com,就返回2个ip 说明array gethostbynamel ( string $hostname )Returns a list of IPv4 a
今天看到几个函数,可以根据ip地址 / 域名 获取对应的 域名 / ip 的函数。记录于此。
说明 array gethostbynamel ( string $hostname ) Returns a list of IPv4 addresses to which the Internet host specified by hostname resolves. 参数 hostname The host name. 返回值 Returns an array of IPv4 addresses or FALSE if hostname could not be resolved.
gethostbyname($hostname) // 根据域名获取IP,只返回第一个IP
gethostbyname — Get the IPv4 address corresponding to a given Internet host name 说明 string gethostbyname ( string $hostname ) Returns the IPv4 address of the Internet host specified by hostname. 参数 hostname The host name. 返回值 Returns the IPv4 address or a string containing the unmodified hostname on failure.
gethostbyaddr($ip) // 根据IP 获取域名
gethostbyaddr — Get the Internet host name corresponding to a given IP address 说明 string gethostbyaddr ( string $ip_address ) Returns the host name of the Internet host specified by ip_address. 参数 ip_address The host IP address. 返回值 Returns the host name on success, the unmodified ip_address on failure, or FALSE on malformed input.
例子:
核心 destoon 基于PHP+MySQL,采用标准化开发,易用性、扩展性、标准性强 会员 member 会员注册、登录,在线销售,企业推广,结交商友,获取商机 公司 company VIP等级体系、实名认证体系、自动二级、顶级域名精美商铺 商城 mall 支持购物车、在线购买,卖家评论打分、交易记录,支持支付宝担保交易 供应 sell 产品供应、展示,在线询价、对比 求购
0
<span>$hostname</span> = 'www.baidu.com'<span>; </span><span>$addr</span> = '127.0.0.1'<span>; </span><span>print_r</span>(<span>gethostbyname</span>(<span>$hostname</span><span>)); </span><span>echo</span> '<br>'<span>; </span><span>print_r</span>(<span>gethostbyaddr</span>(<span>$addr</span><span>)); </span><span>echo</span> '<br>'<span>; </span><span>print_r</span>(<span>gethostbynamel</span>(<span>$hostname</span>));
输出
立即学习“PHP免费学习笔记(深入)”;
220.181.111.148 idc-wang Array ( [0] => 220.181.111.148 [1] => 220.181.112.143 )
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号