分析攻擊IP來源地並畫出餅圖
此文中的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")
gevent協程併發版
#!/usr/bin/python
# coding=utf-8
'''
http://ip-api.com/json/ip
'''
import plotly
import plotly.graph_objs as abcc
import plotly.plotly
class Piecharts:
def __init__(self):
print u'餅圖生成中'
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 = {}
def locater(url):
try:
result = requests.get(url)
jsontext = result.json()
except:
print "Error: Data not retrieved!"
return
status = jsontext['status']
if status == 'fail':
print "%s failed!" % ip.strip()
return
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!"
from gevent import monkey
monkey.patch_socket()
from gevent import pool
import gevent
pool = pool.Pool(40)
glist = []
with open(iplist) as f:
for ip in f.readlines():
if ip.strip() != '':
url = 'http://ip-api.com/json/' + ip.strip()
glist.append(pool.spawn(locater, url))
gevent.joinall(glist)
# 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")
餅圖效果:
相關文章
- pandas讀取csv檔案資料並使用matplotlib畫折線圖和餅圖
- SIM Jacker攻擊分析
- 加密你的資料並使其免受攻擊者的攻擊加密
- TCP/IP協議的SYN攻擊TCP協議
- echarts 餅圖巢狀 二級餅圖 子餅圖 複合餅圖Echarts巢狀
- Quart2D 畫圖二 (餅狀圖、柱狀圖)
- Hundred Finance 攻擊事件分析NaN事件
- CSRF 攻擊深入淺出
- 隱秘的攻擊形式:無檔案攻擊型別分析型別
- 網路攻擊中常見掩蓋真實IP的攻擊方式及虛假IP地址追蹤溯源方法
- android 自定義帶動畫的統計餅圖Android動畫
- 衝擊IPO,羅胖畫了一張終身教育大餅
- 餅圖
- DarkHotel定向攻擊樣本分析
- Hacking Team攻擊程式碼分析
- TARA攻擊樹分析方法論
- Web攻擊日誌分析的過去現在與未來Web
- 【漏洞分析】Penpie 攻擊事件:重入攻擊構造獎勵金額事件
- SQL隱碼攻擊導圖SQL
- Android 折線圖之hellocharts (餅狀圖)餅圖Android
- 【漏洞分析】ReflectionToken BEVO代幣攻擊事件分析事件
- Aseprite+Cocos:打包畫素畫圖,匯入到cocos裡並動起來
- 漫畫:什麼是中間人攻擊
- PHP獲取IP地址的方法,防止偽造IP地址注入攻擊PHP
- CSRF攻擊是什麼並且如何防止
- WMI 的攻擊,防禦與取證分析技術之攻擊篇
- 住宅代理IP在網路攻擊中的作用
- Akamai:65.1%的Web應用程式攻擊來自SQL隱碼攻擊AIWebSQL
- Volatility:分析MS10-061攻擊
- 基於TCP反射DDoS攻擊分析TCP反射
- SQL隱碼攻擊關聯分析SQL
- APT34攻擊全本分析APT
- SolarWinds供應鏈攻擊事件分析事件
- 餅圖0625
- 怎麼用matplotlib畫出漂亮的分析圖表
- AI 畫圖真刺激,手把手教你如何用 ComfyUI 來畫出刺激的圖AIUI
- 三星Android OS加密漏洞分析:IV重用攻擊與降級攻擊Android加密
- 【web安全】深入淺出XSS攻擊Web