复活GoAgent
来源:互联网 发布:河北兰科网络集团 编辑:程序博客网 时间:2024/04/28 23:41
脚本代码如下:
#!/usr/bin/python#!coding:utf-8import urllib2import socketimport timeimport reimport sysimport osdef 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-startprint '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 iplistdef banner(): print '参数错误' print '---------------------------------------------------------------------------------' print '--- 本程序支持从文件导入ip,也支持从网页正则提取ip ---' print '--- 用法: ---' print '--- python google.py https://laod.cn/tools/goagent.html ---' print '--- python google.py ip.txt ---' 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()
转载说明:再次复活你的GoAgent | 老D博客
阅读全文
0 0
- 复活GoAgent
- 复活
- 复活
- 复活
- 复活
- 复活
- Goagent
- goAgent
- goagent
- goagent
- GoAgent
- goagent
- goagent
- 机器复活
- XP复活
- 复活SpringSide
- 复活读后感
- 对象复活
- String的equals类和Object的equals类的区别
- AtCoder-RC078 D
- 二叉排序树
- Python学习之元类详解
- android自定义组合控件
- 复活GoAgent
- 视觉里程计(四)
- windows环境下,点击tomcat的startup.bat闪退问题
- 计算机网络
- leetcode#557. Reverse Words in a String III
- AngularJS的启动引导过程
- rocketmq 雪崩后客户端超时
- 游戏行业入行10年一些思考和总结
- 关于UML的一些