diff --git a/httpd.py b/httpd.py index baad8b2..b689d0e 100644 --- a/httpd.py +++ b/httpd.py @@ -56,7 +56,7 @@ class ProxyAPIHandler(BaseHTTPServer.BaseHTTPRequestHandler): """Show available endpoints.""" endpoints = { 'endpoints': { - '/proxies': 'list working proxies (params: limit, proto, country)', + '/proxies': 'list working proxies (params: limit, proto, country, asn)', '/proxies/count': 'count working proxies', '/health': 'health check', } @@ -77,10 +77,11 @@ class ProxyAPIHandler(BaseHTTPServer.BaseHTTPRequestHandler): limit = min(int(params.get('limit', 100)), 1000) proto = params.get('proto', '') country = params.get('country', '') + asn = params.get('asn', '') format = params.get('format', 'json') # Build query - sql = 'SELECT ip, port, proto, country FROM proxylist WHERE failed=0' + sql = 'SELECT ip, port, proto, country, asn FROM proxylist WHERE failed=0' args = [] if proto: @@ -89,6 +90,9 @@ class ProxyAPIHandler(BaseHTTPServer.BaseHTTPRequestHandler): if country: sql += ' AND country=?' args.append(country.upper()) + if asn: + sql += ' AND asn=?' + args.append(int(asn)) sql += ' ORDER BY tested DESC LIMIT ?' args.append(limit) @@ -109,7 +113,8 @@ class ProxyAPIHandler(BaseHTTPServer.BaseHTTPRequestHandler): 'ip': row[0], 'port': row[1], 'proto': row[2], - 'country': row[3] + 'country': row[3], + 'asn': row[4] }) self.send_json({'count': len(proxies), 'proxies': proxies})