-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,66 @@ | ||
from requests import Session, get | ||
|
||
def getSession(login, password): | ||
global ctoken | ||
s = Session() | ||
try: | ||
ctoken = s.get('https://iphub.info/login').text.split('token" content="')[1].split('"')[0] | ||
r = s.post('https://iphub.info/login', data={'_token': ctoken, 'email': login, 'password': password, 'remember': 'on'}) | ||
r.text.split('Logout')[1] | ||
return s | ||
except: | ||
raise Exception('Login failed!') | ||
|
||
def getKeys(session): | ||
keys = [] | ||
r = session.get('https://iphub.info/account') | ||
dem = r.text.split('/apiKey/') | ||
for line in dem: | ||
try: | ||
if dem.index(line) != 0: | ||
keys.append(line.split('"')[0]) | ||
except: | ||
raise Exception('Keys not found!') | ||
return keys | ||
|
||
def getKey(session, id): | ||
try: | ||
return 'MT' + session.get(f'https://iphub.info/apiKey/{id}').text.split('"MT')[1].split('"')[0] | ||
except: | ||
return None | ||
|
||
def regenerateKey(session, id): | ||
try: | ||
session.post(f'https://iphub.info/apiKey/regenerateApiKey/{id}', data={'_token': ctoken}) | ||
return getKey(session, id) | ||
except: | ||
return None | ||
|
||
def generateKey(session): | ||
try: | ||
session.post('https://iphub.info/apiKey/newFree', data={'_token': ctoken}) | ||
return getKey(session, getKeys(session)[0]) | ||
except: | ||
return None | ||
|
||
def checkIP(session, ip): | ||
r = get(url=f'http://v2.api.iphub.info/ip/{ip}', headers={'X-Key': apiKey}).json() | ||
if 'error' in r: | ||
if '86400' in r['error']: | ||
setKey(regenerateKey(session, getKeys(session)[0])) | ||
return checkIP(ip) | ||
else: | ||
return r | ||
else: | ||
return r | ||
|
||
def setKey(key): | ||
global apiKey | ||
apiKey = key | ||
class IPHub: | ||
def __init__(self, login, password): | ||
self.login = login | ||
self.password = password | ||
self.session = self._get_session() | ||
self.ctoken = None | ||
self.api_key = self.get_key(self.get_keys()[0]) | ||
|
||
def _get_session(self): | ||
s = Session() | ||
try: | ||
self.ctoken = s.get('https://iphub.info/login').text.split('token" content="')[1].split('"')[0] | ||
r = s.post('https://iphub.info/login', data={'_token': self.ctoken, 'email': self.login, 'password': self.password, 'remember': 'on'}) | ||
r.text.split('Logout')[1] | ||
return s | ||
except: | ||
raise Exception('Login failed!') | ||
|
||
def get_keys(self): | ||
keys = [] | ||
r = self.session.get('https://iphub.info/account') | ||
dem = r.text.split('/apiKey/') | ||
for line in dem: | ||
try: | ||
if dem.index(line) != 0: | ||
keys.append(line.split('"')[0]) | ||
except: | ||
self.regenerate_key() | ||
return self.get_keys() | ||
return keys | ||
|
||
def get_key(self, id): | ||
try: | ||
return 'MT' + self.session.get(f'https://iphub.info/apiKey/{id}').text.split('"MT')[1].split('"')[0] | ||
except: | ||
return None | ||
|
||
def regenerate_key(self, id): | ||
try: | ||
self.session.post(f'https://iphub.info/apiKey/regenerateApiKey/{id}', data={'_token': self.ctoken}) | ||
return self.get_key(id) | ||
except: | ||
return None | ||
|
||
def generate_key(self): | ||
try: | ||
self.session.post('https://iphub.info/apiKey/newFree', data={'_token': self.ctoken}) | ||
return self.get_key(self.get_keys()[0]) | ||
except: | ||
return None | ||
|
||
def check_ip(self, ip): | ||
r = get(url=f'http://v2.api.iphub.info/ip/{ip}', headers={'X-Key': self.api_key}).json() | ||
if 'error' in r: | ||
if '86400' in r['error']: | ||
self.set_key(self.regenerate_key(self.get_keys()[0])) | ||
return self.check_ip(ip) | ||
else: | ||
return r | ||
else: | ||
return r | ||
|
||
def set_key(self, key): | ||
self.api_key = key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters