-
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
6 changed files
with
105 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include README.MD | ||
include LICENSE |
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,2 +1,14 @@ | ||
# iphub | ||
IPhub.info API wrapper. | ||
<h1 align="center">iphub - IPhub.info API wrapper.</h1> | ||
|
||
<br> | ||
|
||
<h1 align="center"> -How to use?- </h1> | ||
|
||
```python | ||
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) | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from .iphub import * |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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 |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from setuptools import setup | ||
|
||
with open('README.md', 'r', encoding='utf-8') as f: | ||
long_description = f.read() | ||
|
||
setup( | ||
name='iphub', | ||
version='1.0.0', | ||
author='Maehdakvan', | ||
author_email='visitanimation@google.com', | ||
description='IPhub.info API wrapper.', | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
url='https://github.com/DedInc/iphub', | ||
project_urls={ | ||
'Bug Tracker': 'https://github.com/DedInc/iphub/issues', | ||
}, | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
], | ||
packages=['iphub'], | ||
include_package_data = True, | ||
install_requires = ['requests'], | ||
python_requires='>=3.6' | ||
) |