【问题标题】:Does PHP have a built-in alternative to exec("nslookup")?PHP 是否有 exec("nslookup") 的内置替代方案?
【发布时间】:2012-02-01 21:38:27
【问题描述】:

我的 PHP 类中有以下命令:

@exec('nslookup -type=' . $type . ' ' . escapeshellcmd($host), $output);

由于安全限制,它不能在我的服务器上运行(execescapeshellcmd 在 php.ini 中被禁用)。有没有不依赖exec的替代方案?

【问题讨论】:

  • 旁注:对于单个参数,您应该使用escapeshellarg 而不是escapeshellcmd

标签: php shell


【解决方案1】:

你可以使用dns_get_record():

http://www.php.net/dns_get_record

【讨论】:

  • *在 PHP 5.3 及更高版本中(也就是说,它从 5.3 开始在 Windows 上工作——Linux 平台从 5.0 开始就有)
  • @Justin 不正确。它从 5.3 开始就存在于 Windows 中
【解决方案2】:

为此,我使用内置的gethostbyname($hostname):传递一个域名,如果可以找到它则返回IP,否则返回未修改的输入字符串。 gethostbyaddr($ip) 反其道而行之。

另见:
- gethostbyname 文档
- gethostbyaddr 文档

【讨论】:

    【解决方案3】:

    PHP dns_get_record() 函数是一种简单的方法。但是,请注意,如果用户更改了他们的 hosts 文件,dns_get_record() 将返回 hosts 文件中设置的值,而不是查询权威的 DNS 服务器。

    【讨论】:

      猜你喜欢
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      相关资源
      最近更新 更多