#!/usr/bin/env python3
import requests
import socket
import threading
def server(port, upstream):
assert type(port) is int
assert port >= 0 and port <= 65535
assert type(upstream) is str
assert upstream.startswith('https://')
udp_sock =
socket.socket(socket.AF_INET, socket.SOCK_DGDAM, socket.IPPROTO_UDP)
sock.bind(('127.0.0.1', port))
requests_session = requests.Session()
def handle(request, peer):
nonlocal udp_sock
response = requests_session.post(upstream, data=request, timeout=10)
assert response.status_code == 200
udp_sock.sendto((peer, response.content))
threads = []
while True:
request, peer = udp_sock.recv(65539)
new_thread = threading.Thread(target=handle, args=(request))
threads.append(new_thread)
threads.start()
Python的縮排很重要,這個語言是利用縮排來表示陳述式塊開始和結束的。而你這樣程式是無法運行的,建議先放在 https://github.com 或者 https://del.dog ,再給個link會更好。用markdown也可以。。
2 个赞
Markdown 对代码的支持可以说是非常好的,使用 ```python
与 ```
包括住代码,就能渲染出高亮效果的 python 代码。
点击本回复右上角的编辑历史按钮应该就能看到 Markdown 格式的原文。
#!/usr/bin/env python3
import requests
import socket
import threading
def server(port, upstream):
assert type(port) is int
assert port >= 0 and port <= 65535
assert type(upstream) is str
assert upstream.startswith('https://')
udp_sock =
socket.socket(socket.AF_INET, socket.SOCK_DGDAM, socket.IPPROTO_UDP)
sock.bind(('127.0.0.1', port))
requests_session = requests.Session()
def handle(request, peer):
nonlocal udp_sock
response = requests_session.post(upstream, data=request, timeout=10)
assert response.status_code == 200
udp_sock.sendto((peer, response.content))
threads = []
while True:
request, peer = udp_sock.recv(65539)
new_thread = threading.Thread(target=handle, args=(request))
threads.append(new_thread)
threads.start()
@Calloway
@匿名用户
@Mike_Henry
@Chocolate
b''.fromhex('e58fa6e5a496e68f90e4b880e4b88befbc8ce68891e698afe4b98be5898de79a842063616c6c6f776179207c206a61697a207c20e585ade4bd8de5afb9e695b0e8a1a8efbc8ce68891e4b98be5898de8bf98e6b2a1e69c89e69186e884b1e5a299e58685e79a84e6b497e88491efbc8ce7bb99e5a4a7e5aeb6e5b8a6e69da5e79a84e9babbe783a6efbc8ce68891e8a1a8e7a4bae99d9ee5b8b8e68ab1e6ad89efbc81').decode('utf-8')
1 个赞