分析攻击IP来源地与防御IP攻击的应对策略

分布式拒绝服务(DDoS)攻击指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一个或多个目标发动DDoS攻击,从而成倍地提高拒绝服务攻击的威力。通常,攻击者使用一个偷窃帐号将DDoS主控程序安装在一个计算机上,在一个设定的时间主控程序将与大量代理程序通讯,代理程序已经被安装在网络上的许多计算机上。代理程序收到指令时就发动攻击。利用客户/服务器技术,主控程序能在几秒钟内激活成百上千次代理程序的运行。

此文中的API将台湾列为国家,非本人立场,台湾属于中国,台湾岛生活的人不一定!
上码:

#!/usr/bin/python
#coding=utf-8
'''
http://ip-api.com/json/ip
'''import plotly 
import plotly.plotly 
import plotly.graph_objs as abcc 
import plotly.plotly 

class Piecharts: 
  def __init__(self): 
    print "饼图生成中" 

  def makePiecharts(self,labels,values,filename): 
    trace = abcc.Pie(labels = labels,values= values) 
    plotly.offline.plot([trace],filename=filename) 

import requests
import sys

try:
  iplist = sys.argv[1]
except:
  print "IP list not given or some other error!"
countrylist = {}
regionlist = {}
citylist = {}

with open(iplist) as f:
  for ip in f.readlines():
    if ip.strip() != '':
      url = 'http://ip-api.com/json/' + ip.strip()
      try:
        result = requests.get(url)
        jsontext = result.json()
      except:
        print "Error: Data not retrieved!"
        continue
      status = jsontext['status']
      if status == 'fail':
        print "%s failed!" % ip.strip()
        continue
      mline = jsontext['as']
      city = jsontext['city']
      country = jsontext['country']
      countryCode = jsontext['countryCode']
      isp = jsontext['isp']
      lat = jsontext['lat']
      lon = jsontext['lon']
      org = jsontext['org']
      query = jsontext['query']
      region = jsontext['region']
      regionName = jsontext['regionName']
      timezone = jsontext['timezone']
      zipcode = jsontext['zip']

      if not country in countrylist:
        countrylist[country] = 0
      else:
        countrylist[country] += 1

      if not regionName in regionlist:
        regionlist[regionName] = 0
      else:
        regionlist[regionName] += 1

      if not city in citylist:
        citylist[city] = 0
      else:
        citylist[city] += 1
      try:
        print ip.strip() + '--' + country + '--' + regionName
      except:
        print "Special character!"
  print countrylist

  #country
  labels = [i for i in countrylist] 
  value = [countrylist[i] for i in countrylist] 
  drive = Piecharts() 
  drive.makePiecharts(labels,value,"country.html") 

  #region
  labels = [i for i in regionlist] 
  value = [regionlist[i] for i in regionlist] 
  drive = Piecharts() 
  drive.makePiecharts(labels,value,"region.html") 

  #city
  labels = [i for i in citylist] 
  value = [citylist[i] for i in citylist] 
  drive = Piecharts() 
  drive.makePiecharts(labels,value,"city.html") 


      

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/1461.html