Задания практики выполнены. Скрины с Wireshark'а - в отчёте
This commit is contained in:
parent
e18833e0be
commit
ec597874e1
10
http_socket.py
Normal file
10
http_socket.py
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect(('vyatsu.ru', 80))
|
||||
request = "GET / HTTP/1.1\r\nHost: vyatsu.ru\r\n\r\n"
|
||||
client.sendall(request.encode())
|
||||
response = client.recv(4096)
|
||||
print(response.decode())
|
||||
client.close()
|
10
tcp_client.py
Normal file
10
tcp_client.py
Normal file
@ -0,0 +1,10 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect(('127.0.0.1', 12000)) # порт 12000
|
||||
client.sendall(b'hello server')
|
||||
data = client.recv(1024)
|
||||
print(f"Ответ от сервера: {data.decode(errors='ignore')}")
|
||||
client.close()
|
||||
|
||||
|
22
tcp_server.py
Normal file
22
tcp_server.py
Normal file
@ -0,0 +1,22 @@
|
||||
import socket
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.bind(("0.0.0.0", 12000))
|
||||
server.listen(1)
|
||||
print("TCP сервер запущен на порту 12000")
|
||||
|
||||
while True:
|
||||
conn, addr = server.accept()
|
||||
print(f"Подключение от {addr}")
|
||||
|
||||
data = conn.recv(1024)
|
||||
if not data:
|
||||
break
|
||||
|
||||
conn.sendall(b'#' + b'#'.join(bytes([b]) for b in data))
|
||||
|
||||
conn.close()
|
||||
|
||||
if data.upper() == b'EXIT':
|
||||
break
|
||||
|
13
token_read.py
Normal file
13
token_read.py
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
import requests
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv("GITEA_TOKEN")
|
||||
headers = {"Authorization": f"token {TOKEN}"}
|
||||
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||
print(response.json())
|
16
token_write_repo.py
Normal file
16
token_write_repo.py
Normal file
@ -0,0 +1,16 @@
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
TOKEN = os.getenv("GITEA_TOKEN_WRITE")
|
||||
headers = {"Authorization": f"token {TOKEN}"}
|
||||
|
||||
data = {
|
||||
"name": "repoZadanie4_rabota_s_Gitea_3laba",
|
||||
"private": False,
|
||||
"description": "Репозиторий, созданный с помощью API"
|
||||
}
|
||||
|
||||
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", headers=headers, json=data)
|
||||
print(response.json())
|
8
udp_client.py
Normal file
8
udp_client.py
Normal file
@ -0,0 +1,8 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
client.sendto(b'hello server', ('127.0.0.1', 13001))
|
||||
data, _ = client.recvfrom(1024)
|
||||
print(f"Ответ от сервера: {data.decode(errors='ignore')}")
|
||||
client.close()
|
||||
|
12
udp_server.py
Normal file
12
udp_server.py
Normal file
@ -0,0 +1,12 @@
|
||||
import socket
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
server.bind(('0.0.0.0', 13001)) # уникальный порт
|
||||
print("UDP сервер запущен на порту 13001")
|
||||
|
||||
while True:
|
||||
data, addr = server.recvfrom(1024)
|
||||
print(f"Сообщение от {addr}: {data.decode()}")
|
||||
|
||||
server.sendto(b'#' + b'#'.join(bytes([b]) for b in data), addr)
|
||||
|
4
zadanie2_http_request.py
Normal file
4
zadanie2_http_request.py
Normal file
@ -0,0 +1,4 @@
|
||||
import requests
|
||||
|
||||
response = requests.get("http://vyatsu.ru")
|
||||
print(response.text[:500])
|
17
zadanie3_http_socket.py
Normal file
17
zadanie3_http_socket.py
Normal file
@ -0,0 +1,17 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect(('vyatsu.ru', 80))
|
||||
request = (
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"Host: vyatsu.ru\r\n"
|
||||
"User-Agent: python-requests/2.31.0\r\n"
|
||||
"Accept-Encoding: gzip, deflate\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"Connection: keep-alive\r\n"
|
||||
"\r\n"
|
||||
)
|
||||
client.sendall(request.encode())
|
||||
response = client.recv(4096)
|
||||
print(response.decode(errors="ignore"))
|
||||
client.close()
|
Loading…
Reference in New Issue
Block a user