Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef25370

Browse files
committed
print MX record
1 parent 29b1606 commit ef25370

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Demo/dns/asgethost.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sys
2+
import dnslib
3+
import dnstype
4+
import dnsopcode
5+
import dnsclass
6+
import socket
7+
import select
8+
9+
def main():
10+
server = 'cnri.reston.va.us' # How?
11+
port = 53
12+
opcode = dnsopcode.QUERY
13+
rd = 0
14+
qtype = dnstype.MX
15+
qname = sys.argv[1:] and sys.argv[1] or 'www.python.org'
16+
m = dnslib.Mpacker()
17+
m.addHeader(0,
18+
0, opcode, 0, 0, rd, 0, 0, 0,
19+
1, 0, 0, 0)
20+
m.addQuestion(qname, qtype, dnsclass.IN)
21+
request = m.getbuf()
22+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
23+
s.connect((server, port))
24+
s.send(request)
25+
while 1:
26+
r, w, x = [s], [], []
27+
r, w, x = select.select(r, w, x, 0.333)
28+
print r, w, x
29+
if r:
30+
reply = s.recv(1024)
31+
u = dnslib.Munpacker(reply)
32+
dnslib.dumpM(u)
33+
break
34+
35+
main()

0 commit comments

Comments
 (0)