how to write nslookup programmatically?

nonopolarity picture nonopolarity · May 27, 2009 · Viewed 7.9k times · Source

instead of using exec in our script to do an nslookup, is there an easy way to write it programmatically in PHP, Python, or Ruby?

Answer

Andre Miller picture Andre Miller · May 27, 2009

Yes, although the function names might not be what you expect.

Since the Python and Ruby answers are already posted, here is an PHP example:

$ip = gethostbyname('www.example.com');
$hostname = gethostbyaddr('127.0.0.1');