import http.server
import socketserver
import ssl
import requests
import json
PORT = 5000 # Set port to the desired port number
HOST = 'sub1.kalkikrivadna.com' # Specify your subdomain here
class VPNDetectionHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path.startswith('/check-vpn'):
self.do_GET_with_prefix('check-vpn')
else:
html = '''
DEMONSTRATION: Detects and Blocks Proxies, SOCKS4/4a & SOCKS5/5h, The Onion Router (TOR), Mysterium Network Nodes, Web Proxies, Compromised Servers, and more.
'''
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(html.encode())
def do_GET_with_prefix(self, prefix):
"""Handle special routes"""
if self.path.startswith(f'/{prefix}'):
# VPN Check Route
if prefix == 'check-vpn':
# Extract IP from query parameter
ip = self.path.split('?ip=')[1] if '?ip=' in self.path else None
if not ip:
self.send_error(400, "IP not provided")
return
try:
# Use proxycheck.io to verify VPN
vpn_check_url = f'https://proxycheck.io/v2/{ip}?key=28bkv6-lm5vi6-g8063j-569463&vpn=1'
response = requests.get(vpn_check_url)
vpn_data = response.json()
# Determine if it's a VPN
is_vpn = (vpn_data.get(ip, {}).get('proxy') == 'yes')
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps({
'ip': ip,
'is_vpn': is_vpn
}).encode())
except Exception as e:
self.send_error(500, f"VPN Check Failed: {str(e)}")
def run(server_class=http.server.HTTPServer, handler_class=VPNDetectionHandler, port=PORT):
"""Run the HTTPS server."""
server_address = (HOST, port) # Bind to the specified HOST
httpd = server_class(server_address, handler_class)
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
certfile = '/etc/letsencrypt/live/sub1.kalkikrivadna.com/fullchain.pem'
keyfile = '/etc/letsencrypt/live/sub1.kalkikrivadna.com/privkey.pem'
context.load_cert_chain(certfile=certfile, keyfile=keyfile)
httpd.socket = context.wrap_socket(httpd.socket, server_side=True)
print(f'Starting HTTPS server on https://{HOST}:{port}...')
try:
httpd.serve_forever()
except KeyboardInterrupt:
print('\nShutting down the server...')
except Exception as e:
print(f"Server error: {e}")
finally:
httpd.socket.close()
# Main execution block
if __name__ == "__main__":
run(port=PORT) # Pass 'port' as a positional argument