import ipaddress, socket, requests, flask from urllib.parse import urlparse app = flask.Flask(__name__) app.flag = '***CENSORED***' def valid_ip(ip): try: result = ipaddress.ip_address(ip) # Stay out of my private! return result.is_global except: return False def valid_fqdn(fqdn): return valid_ip(socket.gethostbyname(fqdn)) def get(url, recursive_count=0): r = requests.get(url, allow_redirects=False) if 'location' in r.headers: if recursive_count > 2: return '🤔' url = r.headers.get('location') if valid_fqdn(urlparse(url).netloc) == False: return '🤔' return get(url, recursive_count + 1) return r.text @app.route('/admin-status') def admin_status(): print('Remote Address:', flask.request.remote_addr) if flask.request.remote_addr != '127.0.0.1': return '🥺' return app.flag @app.route('/check-status') def check_status(): url = flask.request.args.get('url', '') if valid_fqdn(urlparse(url).netloc) == False: return '🥺' return get(url) @app.route('/') def index(): return '''

urlcheck v2

{{ d(status) }}
'''