diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/__pycache__/pybusedb.cpython-37.pyc b/__pycache__/pybusedb.cpython-37.pyc index ab9b25e..b60b8fb 100644 Binary files a/__pycache__/pybusedb.cpython-37.pyc and b/__pycache__/pybusedb.cpython-37.pyc differ diff --git a/pybusedb.py b/pybusedb.py index f13f225..1e37480 100644 --- a/pybusedb.py +++ b/pybusedb.py @@ -15,5 +15,12 @@ class APIConnect(object): def checkIP(self, ip): self.ip = ip - self.URL = self.baseAPIURL + self.checkIPURL + self.ip + '/json' '?key=%s' % self.APIKEY - print(self.URL) + #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 + print(self.URL) + r = requests.get(self.URL) + jsonData = r.json() + return jsonData + else: + return "Invalid IP" diff --git a/test.py b/test.py new file mode 100644 index 0000000..7c03ae4 --- /dev/null +++ b/test.py @@ -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)