Python之scapy路由跟蹤模塊

模塊:scapy

簡介:可以檢測路由路徑並將圖片展示給用戶

#需要安裝軟件包ImageMagick和graphviz#
#-*-coding:utf-8 -*-
def traceroute():
	import time,sys
	import logging,warnings
	import subprocess
	from scapy.all import traceroute
	warnings.filterwarnings("ignore",category=DeprecationWarning)		#屏蔽scapy無用的告警信息
	logging.getLogger("scapy.runtime").setLevel(logging.ERROR)			#屏蔽IPv6多餘告警
	domains = "www.laosiji.com"											#定義跟蹤的url
	dport = [80,443]
	target = domains.split(' ')
	if len(target) >= 1 and target[0]!='':								#判斷url是否爲空值
	    res,unans = traceroute(target,dport=dport,retry=-2)			#定義跟蹤
	    res.graph(target="> traceroute.svg")							#輸出svg
	    time.sleep(1)
	    subprocess.Popen("/usr/bin/convert traceroute.svg traceroute.png",shell=True)	#將svg轉化爲png
	else:
	    exit()
#traceroute()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章