我有一个excel文件,其中包含每个IP(同一行)的IP和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])
多谢各位
目前没有回答
相关问题 更多 >
编程相关推荐