-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPChecker.py
More file actions
67 lines (53 loc) · 2.39 KB
/
IPChecker.py
File metadata and controls
67 lines (53 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import requests
import json
#import sqlite3
from datetime import datetime
class iptester():
def runthis(self, input, username):
check_list = input.splitlines()
no_duplicated_check_list = list(set(check_list)) #no dublicated ips
output_txt = "out.txt"
filename = 'IPChecker-apikeys.txt'
api_keys = []
with open(filename, 'r') as f:
for line in f:
api_keys.append(line.strip())
counter = 0
# Open the output file
now = datetime.now()
formatted_time = now.strftime("%Y-%m-%d %H:%M:%S")
with open(output_txt, 'w') as f:
# Use the values in a for loop
f.write(f"Scan started by {username} at {formatted_time} \n")
f.write("="*50 + "\n")
for value in no_duplicated_check_list:
base_url = "https://www.virustotal.com/api/v3/ip_addresses/"
url = f"{base_url}{value}"
headers = {
"accept": "application/json",
"x-apikey": api_keys[counter % len(api_keys)]
}
counter = counter + 1
response = requests.get(url, headers=headers)
json_file = json.loads(response.text)
try:
ip_address = json_file["data"]["id"]
#print(ip_address)
as_owner = json_file["data"]["attributes"]["as_owner"]
#print(as_owner)
last_analysis_stats = json_file["data"]["attributes"]["last_analysis_stats"]
#print(last_analysis_stats)
f.write(f"IP Address: {ip_address}\n")
f.write(f"AS Owner: {as_owner}\n")
f.write("Last Analysis Stats:\n")
for engine, result in last_analysis_stats.items():
if isinstance(result, dict):
category = str(result['category'])
method = str(result['method'])
f.write(f"\t{engine}: {category} ({method})\n")
else:
f.write(f"\t{engine}: {result}\n")
f.write("="*50 + "\n")
except:
f.write("error with value="+value+"\n")
f.write("="*50 + "\n")