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?
+1
A:
For Python see http://small-code.blogspot.com/2008/05/nslookup-in-python.html . For much richer functionality, also in Python, see http://www.dnspython.org/ .
Alex Martelli
2009-05-27 19:44:07
The documentation for the Python socket library http://pydoc.org/1.6/socket.html is also very useful. Have a look at:gethostbyname() -- map a hostname to its IP numbergethostbyaddr() -- map an IP number or hostname to DNS info
Andre Miller
2009-05-27 19:49:07
+1
A:
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');
Andre Miller
2009-05-27 19:45:41
+1
A:
For PHP, you can use gethostbyname and gethostbyaddr.
For Python, import the socket module and again use gethostbyname and gethostbyaddr.
Roshan
2009-05-27 19:51:04