Python 官方文档:入门教程 => 点击学习
源代码如下:#coding=gbk import urllib,re import os,sys from bs4 import BeautifulSoup as soup def get_ip(ip): a = [] ur
源代码如下:
#coding=gbk
import urllib,re
import os,sys
from bs4 import BeautifulSoup as soup
def get_ip(ip):
a = []
url = "Http://www.ip138.com/ips138.asp?ip={0}&action=2".fORMat(ip)
opurl = urllib.urlopen(url)
o_data = opurl.read()
opurl.close()
c = soup(o_data)
data = c.find_all("table",{"width":"80%"})
for x in data:
x_l = ''.join(re.findall(u'本站主数据:(.*)',x.li.text))
return ' %s %s \n' % (ip,x_l)
def get_tracert(domain):
ip_list = []
data = os.popen('tracert -d %s ' % domain).readlines()
b = re.compile(r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})')
data = [ b.findall(x) for x in data ]
for x in data:
if x != []:
ip_list.append(''.join(x))
return ip_list
if __name__ == '__main__':
print '访问%s 经过的路由如下:\n' % sys.argv[1]
for x in get_tracert(sys.argv[1]):
print get_ip(x)
保存成tracert.py
执行结果如下:
--结束END--
本文标题: python路由跟踪(闲来无聊写着玩)
本文链接: https://lsjlt.com/news/186303.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0