Added IP lookup functionality to the lib

This commit is contained in:
Benjamyn Love 2018-09-09 05:31:54 +10:00
parent a71db93722
commit b136bf7568
4 changed files with 22 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

Binary file not shown.

View File

@ -15,5 +15,12 @@ class APIConnect(object):
def checkIP(self, ip): def checkIP(self, ip):
self.ip = ip self.ip = ip
#checks to see if we supplied a valid IPv4
if re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', self.ip):
self.URL = self.baseAPIURL + self.checkIPURL + self.ip + '/json' '?key=%s' % self.APIKEY self.URL = self.baseAPIURL + self.checkIPURL + self.ip + '/json' '?key=%s' % self.APIKEY
print(self.URL) print(self.URL)
r = requests.get(self.URL)
jsonData = r.json()
return jsonData
else:
return "Invalid IP"

12
test.py Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/python3
import pybusedb
import json
from pprint import pprint
APIKEY = '213456'
IP = '178.210.90.90'
APIConnector = pybusedb.APIConnect(APIKEY)
data = APIConnector.checkIP(IP)
pprint(data)