0

I have this script

<?php
function get_reverse_dns($Ip)
{
    $result = exec("nslookup -n ".escapeshellarg($Ip)." | grep 'name = '");
    if(strpos($result,"name =") === false)
    {
        return "NO REVERSE";
    }
    else
    {
        $result = trim($result);
        $ExplodedResult = explode("name =",$result);
        $ExplodedResult[1] = trim($ExplodedResult[1]);
        $ReverseDns = trim($ExplodedResult[1],".");
        return $ReverseDns;
    }
}
?>

that gives me the reverse dns, now the problem is that sometimes, an IP can have a really long delay, and i want that this script to check it the IP can be "looked up", and if 5 seconds passed and this is not happening, then return false

How can i make that?

I have tried in linux

nslookup --timeout 5 1.1.1.1 | grep 'name = '
timeout 5 nslookup 1.1.1.1 | grep 'name = '

Thanks.

4

2 回答 2

0

You want to check man nslookup that will give you that the command should be:

nslookup -timeout 5 1.1.1.1 | grep 'name = '

You have one too many -'s

于 2013-08-07T13:19:38.547 回答
0

I would use dig: dig -x ${ip} +time=5 +tries=1 +retry=0 +short

This command will only return the IP address so it will simplify your parsing bit.

于 2013-08-07T13:20:59.180 回答