程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Weibu Online Cloud API-python batch detection IP script

編輯:Python

Weibu Online CloudAPI-python批量檢測IP腳本

IP 信譽

For inbound scenariosIP進行分析, 能夠提供IP的地理位置、ASN信息,Accurately identify through the judgment rulesIP是否惡意、Risk severity level、Confidence level;Identify threat types,如:漏洞利用(exploit)、傀儡機(Zombie)、代理(Proxy)、可疑(Suspicious)etc. and associated security incident or gang tags.

Weibu OfficialAPI 調用文檔:https://x.threatbook.com/v5/apiDocs

實現代碼

import requests
from jsonpath import jsonpath
import openpyxl
file_name="ips.xlsx" # execl文件需要自己創建
read_xlsx = openpyxl.load_workbook(file_name) # 讀取文件
readSheet1 = read_xlsx["Sheet1"] # 使用Sheet1工作表
readSheet1.delete_rows(readSheet1.min_row, readSheet1.max_row) # 清空文件內容
readSheet1.append(['IP地址', '嚴重級別', '是否惡意IP', '可信度', '威脅類型', 'IP歸屬地', '最近更新時間', '應用場景'])
url = "https://api.threatbook.cn/v3/scene/ip_reputation"
# 待查ip列表
strs=''' 37.44.238.161 141.98.83.139 39.100.73.242 40.118.131.195 167.99.190.147 192.241.219.240 104.248.136.93 121.40.210.60 128.1.91.205 '''
ips = [i for i in strs.strip().split("\n")]
for ip in ips:
query = {

"apikey": "", # <=====你的api內容
"resource": ip,
"lang": "zh"
}
response = requests.request("GET", url, params=query)
result = response.json()
a2 = jsonpath(result, "$..severity")
a3 = jsonpath(result, "$..is_malicious")
a4 = jsonpath(result, "$..confidence_level")
a5 = ",".join(jsonpath(result, "$..judgments")[0])
a6 = "-".join(jsonpath(result, "$..location.*")[0:3])
a7 = jsonpath(result, "$..update_time")
a8 = jsonpath(result, "$..scene")
l = [ip, *a2, *a3, *a4, a5, a6, *a7, *a8]
readSheet1.append(l)
read_xlsx.save(file_name)

The effect of the file generated after execution


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved