Skip to content

Commit

Permalink
technical(check): prevent DDoS on checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Placidina committed Apr 28, 2019
1 parent dba1db6 commit 2968c25
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions getproxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ProxyNova, ProxyHTTP, CheckerProxy, FreeProxyList


# sys.tracebacklimit = 0
sys.tracebacklimit = 0
CONFIG = json.load(open('config.json'))


Expand Down Expand Up @@ -49,6 +49,8 @@ def parse_args():
parser.add_argument('--all-no', default=[], help='All proxies except')
parser.add_argument('--check', default=False,
action='store_true', help='Verify the proxies is working')
parser.add_argument('--check-url', required='--check' in sys.argv,
dest='checker', help='Url to checke your current ip')

try:
return parser.parse_args()
Expand All @@ -72,8 +74,9 @@ def run(self):

self.log('GetProxies initialized')

self.current_ip = self.get_current_ip()
self.log('Your Current IP: \033[93m{}'.format(self.current_ip))
if self.args['checker']:
self.current_ip = self.get_current_ip()
self.log('Your Current IP: \033[93m{}'.format(self.current_ip))

all_no = []
if self.args['all_no']:
Expand Down Expand Up @@ -125,9 +128,13 @@ def get_current_ip(self):
"""

try:
resp = requests.get('http://checkip.amazonaws.com',
resp = requests.get(self.args['checker'],
headers=self.headers, timeout=15)
return resp.text.replace('\n', '')
match = re.search(r'([0-9]{1,3}\.){3}[0-9]{1,3}', resp.text)
if match:
return match.group(0)
else:
sys.exit("Unable to retrieve your current IP")
except requests.exceptions.Timeout:
sys.exit("Timeout error to check your current IP")
except requests.exceptions.RequestException:
Expand Down Expand Up @@ -178,7 +185,7 @@ def checker(self, proxies):
result = []
for proxy in proxies:
try:
resp = requests.get('http://checkip.amazonaws.com', headers=self.headers, proxies={'http': '{}:{}'.format(
resp = requests.get(self.args['checker'], headers=self.headers, proxies={'http': '{}:{}'.format(
proxy['ip'], proxy['port']), 'https': '{}:{}'.format(proxy['ip'], proxy['port'])}, timeout=15)
except requests.exceptions.RequestException:
continue
Expand All @@ -201,11 +208,10 @@ def ip_check(self, html):
:return: True or False
"""

html_lines = html.splitlines()
if len(html_lines) == 1:
match = re.match(r'(?:[0-9]{1,3}\.){3}[0-9]{1,3}', html)
if html:
match = re.search(r'([0-9]{1,3}\.){3}[0-9]{1,3}', html)
if match:
if self.current_ip in html:
if self.current_ip == match.group(0):
return False
else:
return False
Expand Down

0 comments on commit 2968c25

Please sign in to comment.