diff --git a/LICENSE b/LICENSE index 980bee9..78e8b23 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,3 @@ -MIT License - Copyright (c) 2022 Vladislav Zenkevich Permission is hereby granted, free of charge, to any person obtaining a copy @@ -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. \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..36d602a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include README.MD +include LICENSE \ No newline at end of file diff --git a/README.md b/README.md index d2a84a8..4b9751a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ -# iphub -IPhub.info API wrapper. +

iphub - IPhub.info API wrapper.

+ +
+ +

-How to use?-

+ +```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) +``` \ No newline at end of file diff --git a/iphub/__init__.py b/iphub/__init__.py new file mode 100644 index 0000000..2175edf --- /dev/null +++ b/iphub/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from .iphub import * \ No newline at end of file diff --git a/iphub/iphub.py b/iphub/iphub.py new file mode 100644 index 0000000..d45a17b --- /dev/null +++ b/iphub/iphub.py @@ -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 \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..bffd770 --- /dev/null +++ b/setup.py @@ -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' +) \ No newline at end of file