python - 使用 API 和 Python 从 Virustotal 检索 IP 位置
问题描述
我有一个 excel 文件,其中包含每个 IP(同一行)的 Ips 和 API 密钥列表,以使用 API 集成从 Virustotal 获取它们的位置。
以下代码适用于一个 IP,但如何检查多个 IP?并获取国家/地区键/值
import requests
url = 'https://www.virustotal.com/vtapi/v2/ip-address/report'
params = {'apikey':'<apikey>','ip':'<ip>'}
response = requests.get(url, params=params)
print(response.json())
Below is my current code .. which reads text file that looks like this( as dictionary )
**Text File:**
apikey #### IP 204.79.197.212
apikey #### IP 204.79.197.212
**Code :**
url = 'https://www.virustotal.com/vtapi/v2/ip-address/report' # targeted url
# use this for IP https://www.virustotal.com/vtapi/v2/ip-address/report
with open('IP.json', 'w') as json_file:
with open('IP.txt') as f:# In this file I have my api key for each domain
for line in f:
counter += 1
tok = line.split()
d[tok[0]] = tok[1] # assign values to dict key
d[tok[2]] = str(tok[3]) #assign values to dict key , 2 keys apikey which is fixed and other key can be domain , ip , etc
response = requests.get(url, params=d) # pass the dict
print(d) # just to print the dict , it works
#print(response.json())
#json.dump(response.json(), json_file)
#jvar=response.json()
#print(jvar)
#print(type(jvar))
with open('IPCSV.csv', 'a', encoding="utf-8") as csv_file:
writer = csv.writer(csv_file, delimiter='>')
for k,v in jvar.items():
print(k,v)
if k == 'country':
print(k,v)
writer.writerow([k, v])
谢谢
解决方案
推荐阅读
- java - 为什么我在线程错误中收到异常?
- javascript - 如何使用 Firefox 运行 puppeteer 测试?
- javascript - 反应路由器dom渲染空白页面
- firebase - 如何在firebase中的特定时间后使数据过期?
- arrays - 来自 API 的产品列表
- javascript - 从嵌套的对象数组中提取数组值
- r - 在 R 中优化简单的 for 循环
- spring-boot - 在 Camel 路由上使用自定义 JMS 侦听器的“containerFactory”
- linux - 如何在我的 cpanel 服务器上显示错误页面而不是在我的目录中显示文件
- html - 如何根据条件连接具有不同字符的名称?