zoukankan      html  css  js  c++  java
  • IP 跟踪

    #coding=utf-8
    import sys
    import os
    import re
    import urllib
    import subprocess

    def getlocation(ip):
       result = urllib.urlopen("http://www.ip138.com/ips.asp?ip=%s&action=2" % ip)
      res = result.readlines()
      result.close()
      for i in res:
        if re.match(".*ul class="ul1".*",i):
          ipblock=i
      if 'ipblock' in dir():
        add1 = ipblock.split("<")[3].split(">")[1].decode('gb2312')[6:].encode('utf8')
        add2 = ipblock.split("<")[5].split(">")[1].decode('gb2312')[6:].encode('utf8')
        if add1 == add2:
          return " "+add1
        else:
          return " "+add1+" OR "+add2

    if len(sys.argv) < 2:
      print "Usage: %s {hostname|ip}" % sys.argv[0]
      sys.exit()
    else:
      host = sys.argv[1]

    try:
      p = subprocess.Popen(['tracert',host],stdout=subprocess.PIPE)
      while True:
        line = p.stdout.readline()
        if not line:
          break
        if re.match("^.[0-9].*(.*).*",line):
          try:
            ip = line.split('(')[1].split(')')[0]
            print line+getlocation(ip)
          except IndexError,e:
            print line,
        else:
          print line,
    except (KeyboardInterrupt,SystemExit):
      sys.exit()

    执行方法,到目录下 tracert.py www.baidu.com

  • 相关阅读:
    Kubernetes笔记 (2)
    Kubernetes笔记(3)
    Kubernetes笔记 (1)
    《深入浅出React和Redux》(4)
    【从0安装】xshell和xftp
    【从0安装】Sourcetree
    postman测试需要登录的接口
    vue自定义滚动条组件-vuebar组件
    charles 抓包http 和 https
    pycharm 面板颜色调整和中文汉化
  • 原文地址:https://www.cnblogs.com/monsteryang/p/6569276.html
Copyright © 2011-2022 走看看