-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_abuse_ipdb.py
executable file
·67 lines (53 loc) · 1.46 KB
/
check_abuse_ipdb.py
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
#!/usr/bin/env python3
import argparse
import requests
import json
from dotenv import dotenv_values
def get_args():
parser = argparse.ArgumentParser(
description='Check whether an IP has been reported to AbuseIPDB',
)
parser.add_argument(
'--ip-address', '-ip-address', '--ip', '-ip', '--i', '-i',
type=str,
required=True,
help='IP Address (eg. 106.75.134.172)'
)
parser.add_argument(
'--verbose', '-verbose', '--v', '-v',
type=bool,
required=False,
default=False,
help='Verbose Output'
)
return parser.parse_args()
def check_abuse_ipdb():
env = dotenv_values('.env')
api_key = env.get('API_KEY', None)
url = 'https://api.abuseipdb.com/api/v2/check'
querystring = {
'ipAddress': ip_address,
'maxAgeInDays': '90'
}
if verbose:
querystring['verbose'] = ''
headers = {
'Accept': 'application/json',
'Key': api_key
}
response = requests.request(
method='GET',
url=url,
headers=headers,
params=querystring
)
if response.status_code >= 500:
print(f'Server error: {response.status_code}')
else:
decodedResponse = json.loads(response.text)
print(json.dumps(decodedResponse, sort_keys=True, indent=4))
if __name__ == '__main__':
args = get_args()
ip_address = args.ip_address
verbose = args.verbose
check_abuse_ipdb()