Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DedInc committed Apr 29, 2023
1 parent e40037e commit a681c47
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 63 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<h1 align="center"> -How to use?- </h1>

```python
import iphub
from iphub import IPHub

s = iphub.getSession('login', 'password') #Authirization
key = iphub.generateKey(s) #Generate/Get key
iphub.setKey(key) #Set key for use
print(iphub.checkIP(s, '127.0.0.1')) #Check ip and print result (note: Auto regenerate key if expired)
iphub = IPHub('rzpsbbdiwg7@1secmail.com', 'rzpsbbdiwg7@1secmail.com')
result = iphub.check_ip('127.0.0.1')
print(result)
```
121 changes: 64 additions & 57 deletions iphub/iphub.py
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='iphub',
version='1.0.0',
version='1.0.1',
author='Maehdakvan',
author_email='visitanimation@google.com',
description='IPhub.info API wrapper.',
Expand Down

0 comments on commit a681c47

Please sign in to comment.