Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DedInc committed Jul 2, 2022
1 parent 0917480 commit e40037e
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 5 deletions.
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
MIT License

Copyright (c) 2022 Vladislav Zenkevich

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -18,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.MD
include LICENSE
16 changes: 14 additions & 2 deletions README.md
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)
```
2 changes: 2 additions & 0 deletions iphub/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from .iphub import *
59 changes: 59 additions & 0 deletions iphub/iphub.py
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
27 changes: 27 additions & 0 deletions setup.py
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'
)

0 comments on commit e40037e

Please sign in to comment.