- A+
所属分类:神兵利刃
最近由于某种原因(大家应该都知道的!!)goagent不能用了主要是谷歌的IP连不上了,后来在freebuf上看到一篇文章:http://www.freebuf.com/articles/others-articles/36452.html
上面给出了可用的谷歌IP,但是没几天大部分的IP都不能用了,只有少数几个可以用,这么多IP总不能一个一个手动尝试吧,累死人的,于是我就寻思着写个脚本来批量检测IP地址是否可用并对可用的IP地址的连接速度进行排序,最后能得到可用的连接速度比较快的IP,只要把这些IP加进goagent的配置文件里就可以继续用啦,亲测速度还可以!!
代码是用python写的,时间比较紧写的比较粗糙,大牛勿喷!!
望好心人多分享一些好的IP地址
下载地址:http://pan.baidu.com/s/1kTHV4mN
源码:
#!/usr/bin/python #!coding:utf-8 import urllib2 import socket import time import re import sys import os def get_connect_time(ipaddress, port): try: socket.setdefaulttimeout(1) s=socket.socket() start=time.time() s.connect((ipaddress, port)) end=time.time() s.close() except: print 'Connect %s timeout' %(ipaddress) end='error' s.close() return '3000' try: socket.setdefaulttimeout(1) s=socket.socket() start=time.time() s.connect((ipaddress, port)) end=time.time() s.close() except: print 'Connect %s timeout' %(ipaddress) end='error' s.close() return '3000' if end!='error': connect_time=end-start print 'found ip %s 连接时间:%s ms' %(ipaddress,str(int(connect_time*1000))) # print connect_time connect_time=int(connect_time*1000) return connect_time else: return '3000' def get_host_file(html): #print html text=r'\d+\.\d+\.\d+\.\d+' ip=re.findall(text, html) #print ip iplist=[] for a in ip: if a in iplist: pass else: iplist.append(a) if '127.0.0.1' in iplist: iplist.remove('127.0.0.1') return iplist return iplist def banner(): print '参数错误' print '---------------------------------------------------------------------------------' print '--- 本程序支持从文件导入ip,也支持从网页正则提取ip ---' print '--- 用法: ---' print '--- python google.py http://www.freebuf.com/articles/others-articles/36452.html-' print '--- python google.py ip.txt ---' print '--- by 羽音 ---' print '---------------------------------------------------------------------------------' def main(): argv=sys.argv #print len(argv) if len(argv)<3: banner() sys.exit(0) if '-f' not in argv and '-u' not in argv: banner() else: urladdress='' filename='' if '-u' in argv: urladdress=argv[argv.index('-u')+1] if '-f' in argv: filename=argv[argv.index('-f')+1] if urladdress=='': handle=open(filename) html=handle.read() else: html=urllib2.urlopen(urladdress) html=html.read() ip=get_host_file(html) print 'found %s ip' %(str(len(ip))) print 'starting connect...' print '------------------------------' usefulip=[] for a in ip: connect_time=get_connect_time(a, 443) #print connect_time if connect_time<=2000: usefulip.append([connect_time, a]) ip=[] for a in range(0, len(usefulip)): min_time_ip=min(usefulip) ip.append(min_time_ip) usefulip.remove(min_time_ip) print ip handle=open('output.txt', 'w') text='' for a in ip: text=text+'|'+a[1] handle.write(text) handle.close() os.popen('output.txt') if __name__ == '__main__': main()
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫