一段github上的一段py 使用iplist.net去反查域名,看看到底有多少个域名指向了一个IP
2015-03-24 20:18
483 查看
使用iplist.net去反查域名,看看到底有多少个域名指向了一个IP
#################################################################################
# iplist.py - Lookup IPs -> Domain and Domain -> IPs from iplist.net #
# Copyrighted: Primal Security Podcast - www.primalsecurity.net #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
#################################################################################
#!/usr/bin/env python
####################################
# Curent URL format: #
# http://iplist.net/74.125.228.73/ #
####################################
import os, urllib, sys, optparse, re
# Function to check file
def checkFile(cfile):
if not os.path.isfile(cfile):
print '[-] ' + cfile + ' does not exist.'
exit(0)
if not os.access(cfile, os.R_OK):
print '[-] ' + cfile + ' access denied.'
exit(0)
print '[+] Fetching URLs from ' +cfile
# Function to perform the lookup
def iplook(ips):
if iplist != None:
iFile = open(iplist, 'r')
for ip in iFile:
ei = ip.split()
i = ei[0]
httpR = urllib.urlopen("http://iplist.net/"+i+"/")
f = httpR.readlines()
for line in f:
if "<h2" in line:
if "</table" in line:
# Formatting line for domain
htm = line.split("<")
html = htm[2]
dom = html.split(">")
domain = str(dom[1])
# Formatting line for IP
i = line.split("/")
ip = str(i[4])
else:
print "##############################"
htm = line.split("<")
html = htm[1]
dom = html.split(">")
domain = str(dom[1])
i = line.split("/")
print i
ip = str(i[3])
l = '%-25s --> %20s' % (domain,ip)
print l
else:
httpR = urllib.urlopen("http://iplist.net/"+ips+"/")
f = httpR.readlines()
for line in f:
if "<h2" in line:
if "</table" in line:
# Formatting line for domain
htm = line.split("<")
html = htm[2]
dom = html.split(">")
domain = str(dom[1])
# Formatting line for IP
i = line.split("/")
ip = str(i[4])
else:
htm = line.split("<")
html = htm[1]
dom = html.split(">")
domain = str(dom[1])
i = line.split("/")
ip = str(i[3])
l = '%-25s --> %20s' % (domain,ip)
print l
def main():
parser = optparse.OptionParser(sys.argv[0] +'-r <file_with_ips> || -i <ip_addr>')
parser.add_option('-i', dest='ip', type='string',help ='specify a target IP')
parser.add_option('-r', dest='ips', type='string',help='specify target file with IPs')
(options, args) = parser.parse_args()
global iplist
global ip
iplist = options.ips
ip = options.ip
if (iplist == None) and (ip == None):
print parser.usage
exit(0)
if iplist != None:
checkFile(iplist)
iplook(iplist)
else:
iplook(ip)
if __name__ == "__main__":
main()
这段代码的结构十分清晰,支持两种输入 一种是-i后面加ip,另一种是-r后面加存有ip的文件。如果是文件则从文件中依次读取出ip 然后通过urllib.urlopen进行访问,从得到html文件中 找出规律 从而 得出结果。
github: https://github.com/primalsecn/python_code/blob/master/iplist.py#L49
#################################################################################
# iplist.py - Lookup IPs -> Domain and Domain -> IPs from iplist.net #
# Copyrighted: Primal Security Podcast - www.primalsecurity.net #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
#################################################################################
#!/usr/bin/env python
####################################
# Curent URL format: #
# http://iplist.net/74.125.228.73/ #
####################################
import os, urllib, sys, optparse, re
# Function to check file
def checkFile(cfile):
if not os.path.isfile(cfile):
print '[-] ' + cfile + ' does not exist.'
exit(0)
if not os.access(cfile, os.R_OK):
print '[-] ' + cfile + ' access denied.'
exit(0)
print '[+] Fetching URLs from ' +cfile
# Function to perform the lookup
def iplook(ips):
if iplist != None:
iFile = open(iplist, 'r')
for ip in iFile:
ei = ip.split()
i = ei[0]
httpR = urllib.urlopen("http://iplist.net/"+i+"/")
f = httpR.readlines()
for line in f:
if "<h2" in line:
if "</table" in line:
# Formatting line for domain
htm = line.split("<")
html = htm[2]
dom = html.split(">")
domain = str(dom[1])
# Formatting line for IP
i = line.split("/")
ip = str(i[4])
else:
print "##############################"
htm = line.split("<")
html = htm[1]
dom = html.split(">")
domain = str(dom[1])
i = line.split("/")
print i
ip = str(i[3])
l = '%-25s --> %20s' % (domain,ip)
print l
else:
httpR = urllib.urlopen("http://iplist.net/"+ips+"/")
f = httpR.readlines()
for line in f:
if "<h2" in line:
if "</table" in line:
# Formatting line for domain
htm = line.split("<")
html = htm[2]
dom = html.split(">")
domain = str(dom[1])
# Formatting line for IP
i = line.split("/")
ip = str(i[4])
else:
htm = line.split("<")
html = htm[1]
dom = html.split(">")
domain = str(dom[1])
i = line.split("/")
ip = str(i[3])
l = '%-25s --> %20s' % (domain,ip)
print l
def main():
parser = optparse.OptionParser(sys.argv[0] +'-r <file_with_ips> || -i <ip_addr>')
parser.add_option('-i', dest='ip', type='string',help ='specify a target IP')
parser.add_option('-r', dest='ips', type='string',help='specify target file with IPs')
(options, args) = parser.parse_args()
global iplist
global ip
iplist = options.ips
ip = options.ip
if (iplist == None) and (ip == None):
print parser.usage
exit(0)
if iplist != None:
checkFile(iplist)
iplook(iplist)
else:
iplook(ip)
if __name__ == "__main__":
main()
这段代码的结构十分清晰,支持两种输入 一种是-i后面加ip,另一种是-r后面加存有ip的文件。如果是文件则从文件中依次读取出ip 然后通过urllib.urlopen进行访问,从得到html文件中 找出规律 从而 得出结果。
github: https://github.com/primalsecn/python_code/blob/master/iplist.py#L49
相关文章推荐
- 在Tomcat中使用一个IP,一个端口,配置多个域名
- 多个网站域名使用同一个IP的设置
- 多个域名网址指向同一个空间IP
- apache中多域名使用同一个ip的方法
- apache中多域名使用同一个ip的方法
- apache rewrite重定向规则,rewrite正则,二级域名指向一级域名,多域名指向一个域名,IP转向域名
- 让你的从godaddy注册的域名指向一个IP
- PHP域名解析(一个IP绑多域名)----看看可以,并不值得借鉴
- IIS tomcat共用80端口解决一个IP多个域名:使用Nginx反向代理方式使两者兼容
- IIS tomcat共用80端口解决一个IP多个域名:使用Nginx反向代理方式使两者兼容
- IIS tomcat共用80端口解决一个IP多个域名:使用Nginx反向代理方式使两者兼容
- (转)IIS tomcat共用80端口解决一个IP多个域名:使用Nginx反向代理方式使两者兼容
- 如何把一个域名指向 服务器。 ( domain to server ip)
- IIS tomcat共用80端口解决一个IP多个域名:使用Nginx反向代理方式使两者兼容
- 测试一个ip两个域名,每个域名指向不同项目
- 动态DNS——本质上是IP变化,将任意变换的IP地址绑定给一个固定的二级域名。不管这个线路的IP地址怎样变化,因特网用户还是可以使用这个固定的域名 这样看的话,p2p可以用哇
- Git使用之GitHub提交一个项目详解
- yii2高级模板使用一个域名管理前后台(url重写)
- github工具使用新手常见问题:Warning: Permanently added the RSA host key for IP address 'X.X.X.X' to the