问题描述
限时送ChatGPT账号..我正在使用 Ubuntu 和 xampp,我正在尝试通过执行命令 nslookup gmail
.PHP,但我得到一个空的响应.当我在 Windows 机器以及运行 CentOS 的 Linux 服务器上尝试时,同样的事情也有效.
I am using Ubuntu and xampp, I am trying to execute the command nslookup gmail
via. PHP, but I am getting an empty response. The same thing worked while I tried on a windows machine as well as in a Linux server running CentOS.
仅供参考 nslookup gmail
当我直接在终端上运行命令时会给出正确的响应,只有当我尝试通过它来执行时才会出现问题.
FYI nslookup gmail
gives proper response when I run the command directly on my terminal, the problem is only when I try to do it via. php.
我什至尝试做一个 which nslookup
然后$nslookup = shell_exec("/usr/bin/nslookup $server");
没有帮助,但同样的空白响应.
I even tried doing a which nslookup
and then
$nslookup = shell_exec("/usr/bin/nslookup $server");
with no help, but the same blank response.
虽然注意命令 whoami
在从 PHP 执行时(我在下面的代码中已经注释过)确实给出了 daemon
Although Note that the command whoami
when executed from PHP(which I have commented in the following code) does give a proper response of daemon
我对 Ubuntu 很陌生,所以一点帮助会很棒.
I am very new to Ubuntu, so a little help would be great.
<?php
$email = $_GET['email'];
$server = explode("@", $email)[1];
echo $server;
$nslookup = shell_exec("nslookup $server");
// $nslookup = shell_exec("whoami");
print_r($nslookup);
?>
推荐答案
当您通过 Web 浏览器执行时,php 脚本将以较低特权的 www 用户(在您的情况下为守护程序)执行.它没有足够的权限来执行命令 nslookup
.我不建议增加 www 用户的权限,这是一个安全风险.作为替代尝试 gethostbyname php 函数.它返回与给定 Internet 主机名对应的 IPv4 地址.
The php script executes as less privileged www user (daemon in your case) when you execute via web browser. It doesn't have enough privilege to execute command nslookup
. I won't recommend increasing privilege of www user, which is a security risk. As an alternative try gethostbyname php function. It returns IPv4 address corresponding to a given Internet host name.
<?php
$email = $_GET['email'];
$server = explode("@", $email)[1];
echo $server;
$ip = gethostbyname($server);
echo $ip;
?>
这篇关于nslookup 查询的 shell_exec 空响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论