#!/usr/bin
# -*- coding:utf-8 -*-
import urllib,urllib2
import re
import subprocess
import sys
output=''
def html(html):
#print str
response=urllib2.urlopen(html)
return str())
def getpage(html):
pattern=re.compile("\.\.\.\s(\d+)",re.S)
#print html
p=(html)
#print '页数为:'+p[0]
if len(p)==0:
print '无查询结果'
exit()
else:
return int(p[0])
def getAllDomain(html):
#print html
pattern1=re.compile("t<a\shref=\"http://(.*?)/\"\srel",re.S)
domain=(html)
result=[]
i=0
#print domain
for pp in domain:
re(pp)
i+=1
return result
def nslookup(domain):
ns=('nslookup '+domain,shell=True,stdout=)
ns_result=ns.()
#print ns_result
#如果nslookup输出不一样需要修改正则,正则不会写,很多疏漏,简单写下能实现就行
re_domain=re.compile("Name:\t([\s\S\w\W]*?)\nAddress:([\s\S\w\W]*?)\n", re.S)
return re_domain.findall(ns_result)
def nslookupThread(allDomain):
for d in allDomain:
r=nslookup(d)
#跳过未查询到的
if len(r)==0:
continue
for i in range(len(r)):
x=r[i][0].strip()
y=r[i][1].strip()
#print '%s:%s' % (x,y)
#提取解析到此ip的域名
if cmp(y,ip)==0:
print x
if __name__ == "__main__":
#
ip='127.0.0.1'
if len)==2:
ip=[1]
else:
print 'usege:. 192.168.1.1'
exit()
url=';+ip+'/'
#查询域名,提取页面数
htmls=html(url)
page=getpage(htmls)
allDomain=[]
print '拉取['+ip+']所有域名,请稍等',
for i in range(1,page+1):
print '.',
newurl=url+str(i)+'/'
htmls=html(newurl)
allDomain+=getAllDomain(htmls)
print '\n共'+str(len(allDomain))+'个域名'
#print allDomain
print '拉取域名完毕'
print '正在查询解析,提取指定ip的域名,请稍等',
nslookupThread(allDomain)
print '查询完毕,已退出'
exit()