-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloopback.py
31 lines (25 loc) · 1.03 KB
/
loopback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from flask import Flask, request
import re
app = Flask(__name__)
# Get your own IP address
def get_own_ip():
return request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
# Handle all requests on all ports and routes
@app.route('/', defaults={'path': ''}, methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'])
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'])
def handle_all(path):
headers = dict(request.headers)
data = request.get_data()
# Replace IP addresses with your own IP address in headers and data
own_ip = get_own_ip()
for key in headers:
headers[key] = re.sub(r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b', own_ip, headers[key])
data = re.sub(r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b', own_ip, data.decode())
response = {
'headers': headers,
'data': data,
'pom=d-input': "https://www.youtube.com/watch?v=kVjrSKPCq_A"
}
return response
if __name__ == '__main__':
app.run(host='0.0.0.0', port=0)