mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-22 17:00:25 +00:00
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@118 e7d03fd6-7b0d-0410-9947-9c21f3af8025
52 lines
1.6 KiB
Python
Executable file
52 lines
1.6 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import DNS
|
|
DNS.ParseResolvConf()
|
|
|
|
def Error(mesg):
|
|
import sys
|
|
print sys.argv[0],"ERROR:"
|
|
print mesg
|
|
sys.exit(1)
|
|
|
|
def main():
|
|
import sys
|
|
if len(sys.argv) != 2:
|
|
Error("usage: %s somedomain.com"%sys.argv[0])
|
|
domain = sys.argv[1]
|
|
nslist = GetNS(domain)
|
|
print "According to the primary, the following are nameservers for this domain"
|
|
for ns in nslist:
|
|
print " ",ns
|
|
CheckNS(ns,domain)
|
|
|
|
|
|
def GetNS(domain):
|
|
import DNS
|
|
r = DNS.Request(domain,qtype='SOA').req()
|
|
if r.header['status'] != 'NOERROR':
|
|
Error("received status of %s when attempting to look up SOA for domain"%
|
|
(r.header['status']))
|
|
primary,email,serial,refresh,retry,expire,minimum = r.answers[0]['data']
|
|
print "Primary nameserver for domain %s is: %s"%(domain,primary)
|
|
r = DNS.Request(domain,qtype='NS',server=primary,aa=1).req()
|
|
if r.header['status'] != 'NOERROR':
|
|
Error("received status of %s when attempting to query %s for NSs"%
|
|
(r.header['status']))
|
|
if r.header['aa'] != 1:
|
|
Error("primary NS %s doesn't believe that it's authoritative!"% primary)
|
|
nslist = map(lambda x:x['data'], r.answers)
|
|
return nslist
|
|
|
|
def CheckNS(nameserver,domain):
|
|
r = DNS.Request(domain,qtype='SOA',server=nameserver,aa=1).req()
|
|
if r.header['status'] != 'NOERROR':
|
|
Error("received status of %s when attempting to query %s for NS"%
|
|
(r.header['status']))
|
|
if r.header['aa'] != 1:
|
|
Error("NS %s doesn't believe that it's authoritative!"% nameserver)
|
|
primary,email,serial,refresh,retry,expire,minimum = r.answers[0]['data']
|
|
print " NS has serial",serial[1]
|
|
|
|
if __name__ == "__main__":
|
|
main()
|