nslookup: support lookup of multiple record types at once
This commit is contained in:
parent
7eddd9b9d7
commit
0038eecfbc
9
bert.py
9
bert.py
|
@ -460,13 +460,12 @@ def command_loop():
|
||||||
except:
|
except:
|
||||||
say(channel, r+"You must specify a domain!")
|
say(channel, r+"You must specify a domain!")
|
||||||
continue
|
continue
|
||||||
try:
|
nstype = msg_parts[2:]
|
||||||
nstype = msg_parts[2]
|
if not nstype:
|
||||||
except:
|
nstype = ["AAAA", "A"]
|
||||||
nstype = "A"
|
|
||||||
print("got nslookup command with domain: "+str(nsdomain)+" and type: "+str(nstype))
|
print("got nslookup command with domain: "+str(nsdomain)+" and type: "+str(nstype))
|
||||||
nsresult = nslookup(nsdomain, nstype)
|
nsresult = nslookup(nsdomain, nstype)
|
||||||
nslines = nsresult.split("\n")
|
nslines = set(nsresult.split("\n"))
|
||||||
for nsline in nslines:
|
for nsline in nslines:
|
||||||
say(channel, y+" "+str(nsline))
|
say(channel, y+" "+str(nsline))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|
25
nslookup.py
25
nslookup.py
|
@ -2,20 +2,21 @@
|
||||||
|
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
|
||||||
def nslookup(domain, typ="AAAA"):
|
def nslookup(domain, types=["AAAA", "A"]):
|
||||||
result = ""
|
result = ""
|
||||||
rcount = 0
|
rcount = 0
|
||||||
try:
|
try:
|
||||||
answer = dns.resolver.resolve(domain, typ)
|
for typ in types:
|
||||||
for rdata in answer:
|
answer = dns.resolver.resolve(domain, typ)
|
||||||
if rcount > 0:
|
for rdata in answer:
|
||||||
result += "\n"
|
if rcount > 0:
|
||||||
if hasattr(rdata, 'exchange'):
|
result += "\n"
|
||||||
result += str(rdata.preference)+" "+str(rdata.exchange)
|
if hasattr(rdata, 'exchange'):
|
||||||
rcount += 1
|
result += str(rdata.preference)+" "+str(rdata.exchange)
|
||||||
else:
|
rcount += 1
|
||||||
result += str(rdata)
|
else:
|
||||||
rcount += 1
|
result += str(rdata)
|
||||||
|
rcount += 1
|
||||||
except dns.resolver.NXDOMAIN as err:
|
except dns.resolver.NXDOMAIN as err:
|
||||||
result = str(err)
|
result = str(err)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -25,7 +26,7 @@ def nslookup(domain, typ="AAAA"):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(nslookup("elmo.space", "AAAA"))
|
print(nslookup("elmo.space"))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user