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://s4.51cto.com/wyfs02/M02/7C/7F/wKioL1bRtaTCZlrTAADROXSsn0c035.png "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://s1.51cto.com/wyfs02/M01/7C/7F/wKioL1bRtNji_PeZAAn5klX5uWU920.png "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 http://linpeisong.blog.51cto.com/9601554/1745661

Python version traceroute and route picture output

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.