我正在使用Python3做代理服务器。想法如下:
首先,创建一个套接字,侦听端口8888,并使用数据获得URL和端口(80/443)
lister = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
lister.bind(("",8888))
lister.listen(5)
while True:
conn, addr = lister.accept()
data = conn.recv(8192)
#get url
url = str(data).split('\\n')[0]
url = str(url).split(' ')[1]
#get FQDN
website = url.replace("http://","")
website = website.split("/")[0]
port = 80
if website.count(":") == 1:
list = website.split(":")
website = list[0]
port = list[1]
print("\033[1;32murl\033[0m: "+str(website)+" \033[1;32mport\033[0m: "+str(port)+"\n")
输出:
然后,我创建一个线程来发送套接字获取的数据,执行该操作的函数是send_data
response = threading.Thread(target=send_data, name="send", args=(website, int(port), conn, dat$
response.start()
带有您的参数的函数send_data
,这将创建另一个套接字,并在其中将前一个套接字的数据发送到指定的目的地和端口。此外,它还会循环执行,以获取新数据并发送。
def send_data(site, port, conn, data, addr):
sender = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sender.connect((site,port))
sender.send(data)
while True:
reply = sender.recv(8192)
if len(reply) > 0:
conn.send(reply)
else:
break
sender.close()
conn.close()
#!/usr/bin/python3
import socket, threading, re, sys, os
# connection socket IPv4 and TCP_IP
def send_data(site, port, conn, data, addr):
sender = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sender.connect((site,port))
sender.send(data)
while True:
reply = sender.recv(8192)
if len(reply) > 0:
conn.send(reply)
else:
break
sender.close()
conn.close()
lister = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
lister.bind(("",8888))
lister.listen(5)
while True:
conn, addr = lister.accept()
data = conn.recv(8192)
#get url
url = str(data).split('\\n')[0]
url = str(url).split(' ')[1]
#get FQDN
website = url.replace("http://","")
website = website.split("/")[0]
port = 80
if website.count(":") == 1:
list = website.split(":")
website = list[0]
port = list[1]
print("\033[1;32murl\033[0m: "+str(website)+" \033[1;32mport\033[0m: "+str(port)+"\n")
response = threading.Thread(target=send_data, name="send", args=(website, int(port), conn, dat$
response.start()
执行脚本并在浏览器127.0.0.1:8888
中配置代理客户端时。这就是结果。
在站点中,字体不是这些,而是通过HTTPS运行的,并且不会运行它,但是FontAwesome图标也是HTTPS,并且已成功执行。什么...?
由于此网站是HTTPS,因此无法运行它。
问题出在具有TLS的https网站中,该网站无法运行。但是HTTP是... 为什么它没有运行?。发生这种情况是因为它无法检查证书TLS?