Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python module for nslookup

Is there a python-module that's doing the same stuff as nslookup does? I am planning to use nslookup on digging some information regarding the domain of a URL to be scrapped. I know I can use os.sys to call nslookup but I am just wondering if there is a python-module for this already. Thanks in advance!

like image 941
jaysonpryde Avatar asked Sep 06 '12 09:09

jaysonpryde


People also ask

What Python function is used to perform a DNS lookup?

Finding Records The dnspython module provides dns. resolver() helps to find out various records of a domain name. The function takes two important parameters, the domain name, and the record type.

How do I send a DNS request in Python?

You will have to grab the request scan through the request for the data you need typically the name of server, then start up a new request using the DNS libary. Trying to just forward a request without altering the raw data typically never works.

What is dig in Python?

Overview. Dig is a command-line program which now communicates with google/youdao translation server. It can be used for look up the words or sentences through google/youdao translation server.


2 Answers

I'm using the following code:

import socket  ip_list = [] ais = socket.getaddrinfo("www.yahoo.com",0,0,0,0) for result in ais:   ip_list.append(result[-1][0]) ip_list = list(set(ip_list)) 

Or using a comprehension as:

ip_list = list({addr[-1][0] for addr in socket.getaddrinfo(name, 0, 0, 0, 0)}) 
like image 71
PajE Avatar answered Oct 04 '22 02:10

PajE


You need to use DNSPython

import dns.resolver  answers = dns.resolver.query('dnspython.org', 'MX') for rdata in answers:     print 'Host', rdata.exchange, 'has preference', rdata.preference 
like image 41
Exos Avatar answered Oct 04 '22 01:10

Exos