Does PHP have a built-in alternative to exec ("nslookup")?

I have the following command in my PHP class:

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

This does not work on my server due to security restrictions ( exec and escapeshellcmd disconnected from php.ini). Is there an alternative that doesn't rely on exec ?

+4
source share
3 answers

You can use dns_get_record() :

http://www.php.net/dns_get_record

+4
source

I use the built-in gethostbyname($hostname) for this: pass it the domain name and it will return ip if it can be found, or an unmodified input line otherwise. gethostbyaddr($ip) goes the other way around.

See also:
- gethostbyname documentation
- gethostbyaddr documentation

0
source

The dns_get_record() PHP function is an easy way to do this. However, keep in mind that if the user modifies his hosts file, dns_get_record() will then return the value specified in the hosts file, rather than querying an authoritative DNS server.

0
source

Source: https://habr.com/ru/post/1394276/


All Articles