-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnxdomain.py
38 lines (33 loc) · 1.01 KB
/
nxdomain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import base64
import dnslib # sudo pip install dnslib
import libgeoip
import common
## called once before .each()
def init(results):
print "% nxdomain.py"
print "@attribute nxd_rt numeric %% response time"
print "@attribute nxd_size numeric %% response size"
print "@attribute nxd_flags numeric %% header bit flags (decimal)"
print "@attribute nxd_rcode numeric %% response code"
print "@attribute nxd_rdata string %% rdata of first answer"
print "@attribute nxd_asn numeric %% answer ASN"
print "@attribute nxd_name string %% answer network name"
## called for each element in result JSON
# pid: probe id
# el: element of the result array
# res: el[result] (just a shortcut)
def each(pid, el, res):
abuf = base64.b64decode(res['abuf'])
rr = dnslib.DNSRecord.parse(abuf)
ip = str(rr.a.rdata)
asn, name = libgeoip.lookup(ip)
return "%.1f,%d,%d,%d,%s,%d,%s" % (
res['rt'],
res['size'],
rr.header.bitmap,
rr.header.rcode,
common.safe(ip),
asn,
name
)
def fail(): return "-1,-1,-1,-1,?,-1,?"