Add lab3 network examples
This commit is contained in:
commit
e66d4fa927
10 files changed
+333
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import socket
|
||||
|
||||
|
||||
HOST = "vyatsu.ru"
|
||||
PORT = 80
|
||||
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect((HOST, PORT))
|
||||
|
||||
request = (
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"Host: vyatsu.ru\r\n"
|
||||
"User-Agent: python-socket-lab3\r\n"
|
||||
"Accept: text/html\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n"
|
||||
)
|
||||
|
||||
client.sendall(request.encode("utf-8"))
|
||||
|
||||
response_parts = []
|
||||
while True:
|
||||
data = client.recv(4096)
|
||||
if not data:
|
||||
break
|
||||
response_parts.append(data)
|
||||
|
||||
client.close()
|
||||
|
||||
response = b"".join(response_parts)
|
||||
print(response.decode("utf-8", errors="replace")[:2000])
|
||||
|
||||
Reference in new issue
Block a user