python 域名解析检测/探测
def version():
pf=platform.system()
return pf+"-"+platform.version() if pf==0 else pf
def os():
if ('Windows' == platform.system()):
return 0
elif ('Linux' == platform.system()):
return 1
def dns(domain,ds):
if os()==0:
try:
cmd=subprocess.check_output("nslookup %s %s" % (domain,ds))
cmd=cmd.decode('gbk')
if "Non-existent domain" in cmd:
return False
pattern = "名称:\s+(\S*)\r\nAddress(es)?:\s+([\d\.]*)"
matchs = re.findall(pattern, cmd)
if not matchs:
return False
return str(matchs[0][2]).strip()
except:
return False
else:
try:
cmd = subprocess.check_output(["/usr/bin/nslookup",domain,ds])
cmd = cmd.decode('utf-8')
if "server can't find" in cmd:
return False
pattern = "Name:\s+(\S*)\nAddress:\s+([\d\.]*)"
matchs = re.findall(pattern, cmd)
if not matchs:
return False
return str(matchs[0][1]).strip()
# return cmd
except:
return False