-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponseParser.py
More file actions
43 lines (31 loc) · 1.06 KB
/
ResponseParser.py
File metadata and controls
43 lines (31 loc) · 1.06 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
import requests
import sys
import json
class ResponseParser:
def __init__(self, verbose):
self.url = "http://ip-api.com/json/"
self.verbose = verbose
def GetParsedData(self, ip):
response = self.GetResponse(ip)
parsed = json.loads(response.text)
if parsed['status'] != 'success':
sys.stderr.write('[-] Could not pull up any info on ip: {0}\n'.format(ip))
del parsed['status']
newdict = {}
keys = parsed.keys()
for key in keys:
if parsed[key] == '':
continue
newdict[key] = parsed[key]
return newdict
def GetResponse(self, ip):
try:
return requests.get(self.url + ip)
except Exception as ex:
sys.stderr.write('Something went wrong with the request to the remote server :( ...\nMore Details: {0}\n'.format(str(ex)))
def Debug():
rp = ResponseParser(True)
response = rp.GetParsedData({your-ip})
print(response)
if __name__ == '__main__':
Debug()