nslookup: support lookup of multiple record types at once
This commit is contained in:
25
nslookup.py
25
nslookup.py
@@ -2,20 +2,21 @@
|
||||
|
||||
import dns.resolver
|
||||
|
||||
def nslookup(domain, typ="AAAA"):
|
||||
def nslookup(domain, types=["AAAA", "A"]):
|
||||
result = ""
|
||||
rcount = 0
|
||||
try:
|
||||
answer = dns.resolver.resolve(domain, typ)
|
||||
for rdata in answer:
|
||||
if rcount > 0:
|
||||
result += "\n"
|
||||
if hasattr(rdata, 'exchange'):
|
||||
result += str(rdata.preference)+" "+str(rdata.exchange)
|
||||
rcount += 1
|
||||
else:
|
||||
result += str(rdata)
|
||||
rcount += 1
|
||||
for typ in types:
|
||||
answer = dns.resolver.resolve(domain, typ)
|
||||
for rdata in answer:
|
||||
if rcount > 0:
|
||||
result += "\n"
|
||||
if hasattr(rdata, 'exchange'):
|
||||
result += str(rdata.preference)+" "+str(rdata.exchange)
|
||||
rcount += 1
|
||||
else:
|
||||
result += str(rdata)
|
||||
rcount += 1
|
||||
except dns.resolver.NXDOMAIN as err:
|
||||
result = str(err)
|
||||
except Exception as err:
|
||||
@@ -25,7 +26,7 @@ def nslookup(domain, typ="AAAA"):
|
||||
return result
|
||||
|
||||
def main():
|
||||
print(nslookup("elmo.space", "AAAA"))
|
||||
print(nslookup("elmo.space"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user