Skip to content

Commit

Permalink
Fix ip checking issue, closes imWildCat#30
Browse files Browse the repository at this point in the history
  • Loading branch information
imWildCat committed Jun 5, 2018
1 parent a2258a5 commit 009d947
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@ out/
scylla.db

# node
node_modules
node_modules

*.bak
19 changes: 12 additions & 7 deletions scylla/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from .loggings import logger
from .tcpping import ping

IP_CHECKER_API = 'http://ipinfo.io'
IP_CHECKER_API_SSL = 'https://ipinfo.io'
IP_CHECKER_API = 'http://api.ipify.org/?format=json'
IP_CHECKER_API_SSL = 'https://api.ipify.org/?format=json'

__CURRENT_IP__ = None

Expand Down Expand Up @@ -53,6 +53,7 @@ def validate_proxy(self):
try:
checking_api = IP_CHECKER_API_SSL if self._using_https else IP_CHECKER_API

# First request for checking IP
r = requests.get(checking_api, proxies={'https': proxy_str, 'http': proxy_str}, verify=False, timeout=15)
if r.ok:
j = json.loads(r.text)
Expand All @@ -61,14 +62,18 @@ def validate_proxy(self):
self._anonymous = True
self._valid = True

# A second request for meta info
r2 = requests.get('https://api.ip.sb/geoip/{}'.format(j['ip']), timeout=15)
jresponse = r2.json()

# Load meta data
# TODO: better location check
meta = {
'location': j['loc'],
'organization': j['org'],
'region': j['region'],
'country': j['country'],
'city': j['city'],
'location': '{},{}'.format(jresponse['latitude'], jresponse['longitude']),
'organization': jresponse['organization'] if 'organization' in jresponse else None,
'region': jresponse['region'],
'country': jresponse['country_code'],
'city': jresponse['city'],
}
self._meta = meta

Expand Down

0 comments on commit 009d947

Please sign in to comment.