[英]How can I resolve a domain name to an IP address when the PHP functions fail?
I need to resolve any given domain in PHP to its corresponding IP address.我需要将 PHP 中的任何给定域解析为其相应的 IP 地址。
gethostbyname
appears to perform a reverse DNS (rDNS) and isn't useful for obtaining the IP address of a domestic connection (that doesn't have direct rDNS).gethostbyname
似乎执行反向 DNS (rDNS),对于获取国内连接(没有直接 rDNS)的 IP 地址没有用。
I have the following, which of course doesn't work:我有以下内容,当然这不起作用:
<?php
if (ISSET($_POST["domain"])) {
require_once("/protected/db.php");
echo gethostbyname($_POST["domain"]);
}
echo "Error";
?>
Using dns_get_record
returns Array ( )
and doesn't appear to work as PHP prints Array ( )
when I try the below code from this answer:使用
dns_get_record
返回Array ( )
并且当我尝试此答案中的以下代码时,它似乎无法像 PHP 打印Array ( )
那样工作:
$result = dns_get_record($_POST["domain"],DNS_ALL);
print_r($result);
How can I do this?我怎样才能做到这一点?
You probably want to use dns_get_record()你可能想使用dns_get_record()
I would strongly advise against cybermonkey's solution, as shell_exec() (a) is platform-dependent, and (b) can have major security issues.我强烈建议不要使用 Cybermonkey 的解决方案,因为 shell_exec() (a) 依赖于平台,并且 (b) 可能存在重大安全问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.