shell_exec empty response for nslookup query

若如初见. 提交于 2019-12-13 16:08:20

问题


I am using Ubuntu and xampp, I am trying to execute the command nslookup gmail.com 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.

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.

I even tried doing a which nslookup and then $nslookup = shell_exec("/usr/bin/nslookup $server"); with no help, but the same blank response.

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

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);
?>

回答1:


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;
?>


来源:https://stackoverflow.com/questions/33974037/shell-exec-empty-response-for-nslookup-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!