Python version traceroute and route picture output

Source: Internet
Author: User

Python's traceroute feature makes it easy to implement with Scapy templates, and it's intuitive to output routed images.

Here is a description of the code that modifies the Python automated operations: technology and best practices.

#!/usr/bin/evn python#-*-coding:utf-8 -*-import timeimport logging,warningsimport  Subprocessimport socket# eclipse Pydev prompt Unresolve, but normal operation from scapy.all import  traceroute  #  @UnresolvedImportwarnings. Filterwarnings ("Ignore", category=deprecationwarning)  logging.getlogger ("Scapy.runtime"). SetLevel (Logging. ERROR)  domains = raw_input (' please input domains or ips:  ') #  Method of resolving domain names using socket  # try:#     ip = socket.gethostbyname (domains) #  except socket.error,e:#     print  "You should run by  root "' Try:    domain = domains.split ('   ')        res,unans = traceroute (domains,dport=[80,443],retry=-2)     res.graph (target= ">test.svg")     time.sleep (1)      #输Out convert to PNG for optional, Chrome,ie, etc. you can open a. svg file     subprocess. Popen ("/usr/bin/convert test.svg test.png", shell=true) except:    print  "You  shoud run by root or domain error "

Note: The traceroute program requires root to run. The traceroute function can pass in a tabular format with multiple domain/IP, and multiple ports (80 and 443 here)

Here I give the output of Baidu and Google in school traceroute:

650) this.width=650; "src=" Http:// "title=" Baidushurufa_2016-2-27_20-59-52.png "alt=" Wkiol1brtatczlrtaadroxssn0c035.png "width=", "height=" 427 "border=" 0 " Hspace= "0" vspace= "0" style= "width:700px;height:427px;"/>

Baidu on the left, Google on the right. After a mobile CDN resolution, Google finally passed the CDN of the Telecom

650) this.width=650; "src=" Http:// "title=" baidu_ Google_traceroute.png "width=" 650 "height=" 504 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:650PX;HEIGHT:504PX; " alt= "Wkiol1brtnji_pezaan5klx5uwu920.png"/>

This article is from the "Novice PS Welcome Exchange" Blog, please be sure to keep this source

Python version traceroute and route picture output

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.