Выполненение всех пунктов по заданию 2 + pcapng
This commit is contained in:
parent
c18dc5c369
commit
96bc857674
BIN
client-server-1.pcapng
Normal file
BIN
client-server-1.pcapng
Normal file
Binary file not shown.
BIN
client-server-2.pcapng
Normal file
BIN
client-server-2.pcapng
Normal file
Binary file not shown.
21
gitea_api.py
Normal file
21
gitea_api.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
import requests
|
||||
|
||||
TOKEN = os.getenv("GITEA_TOKEN")
|
||||
|
||||
if not TOKEN:
|
||||
print("Токен не найден")
|
||||
raise SystemExit(1)
|
||||
|
||||
headers = {
|
||||
"Authorization": f"token {TOKEN}"
|
||||
}
|
||||
|
||||
response = requests.get(
|
||||
"https://git.vyatsu.ru/api/v1/user",
|
||||
headers=headers,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
print(response.status_code)
|
||||
print(response.text)
|
||||
18
gitea_create_issue.py
Normal file
18
gitea_create_issue.py
Normal file
@ -0,0 +1,18 @@
|
||||
import os
|
||||
import requests
|
||||
|
||||
token = os.getenv("GITEA_TOKEN")
|
||||
if not token:
|
||||
print("Токен не найден")
|
||||
exit()
|
||||
|
||||
url = "https://git.vyatsu.ru/api/v1/repos/stud203985/2task/issues"
|
||||
|
||||
response = requests.post(
|
||||
url,
|
||||
headers={"Authorization": f"token {token}"},
|
||||
json={"title": "Тестовое issue", "body": "Создано через API"}
|
||||
)
|
||||
|
||||
print(response.status_code)
|
||||
print(response.text)
|
||||
BIN
http-requests.pcapng
Normal file
BIN
http-requests.pcapng
Normal file
Binary file not shown.
BIN
http.pcapng
Normal file
BIN
http.pcapng
Normal file
Binary file not shown.
7
http_requests_client.py
Normal file
7
http_requests_client.py
Normal file
@ -0,0 +1,7 @@
|
||||
import requests
|
||||
|
||||
response = requests.get("http://vyatsu.ru", timeout=10)
|
||||
|
||||
print("Статус:", response.status_code)
|
||||
print("Первые 500 символов:")
|
||||
print(response.text[:500])
|
||||
25
http_socket_client.py
Normal file
25
http_socket_client.py
Normal file
@ -0,0 +1,25 @@
|
||||
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-socket-client/1.0\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n"
|
||||
)
|
||||
|
||||
client.sendall(request.encode())
|
||||
|
||||
response = b""
|
||||
while True:
|
||||
part = client.recv(4096)
|
||||
if not part:
|
||||
break
|
||||
response += part
|
||||
|
||||
print(response.decode(errors="replace"))
|
||||
client.close()
|
||||
26
http_socket_client_requeststype.py
Normal file
26
http_socket_client_requeststype.py
Normal file
@ -0,0 +1,26 @@
|
||||
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: close\r\n"
|
||||
"\r\n"
|
||||
)
|
||||
|
||||
client.sendall(request.encode())
|
||||
|
||||
response = b""
|
||||
while True:
|
||||
part = client.recv(4096)
|
||||
if not part:
|
||||
break
|
||||
response += part
|
||||
|
||||
print(response.decode(errors="replace"))
|
||||
client.close()
|
||||
12
tcp_client.py
Normal file
12
tcp_client.py
Normal file
@ -0,0 +1,12 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect(("127.0.0.1", 10000))
|
||||
|
||||
message = input("Введите сообщение: ")
|
||||
client.sendall(message.encode())
|
||||
|
||||
data = client.recv(1024)
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
|
||||
client.close()
|
||||
25
tcp_server.py
Normal file
25
tcp_server.py
Normal file
@ -0,0 +1,25 @@
|
||||
import socket
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.bind(("0.0.0.0", 10000))
|
||||
server.listen(1)
|
||||
|
||||
print("TCP сервер запущен")
|
||||
|
||||
while True:
|
||||
conn, addr = server.accept()
|
||||
print(f"Подключение от {addr}")
|
||||
|
||||
data = conn.recv(1024)
|
||||
if not data:
|
||||
conn.close()
|
||||
continue
|
||||
|
||||
conn.sendall(data.upper())
|
||||
conn.close()
|
||||
|
||||
if data.upper() == b"EXIT":
|
||||
break
|
||||
|
||||
server.close()
|
||||
print("TCP сервер остановлен")
|
||||
11
udp_client.py
Normal file
11
udp_client.py
Normal file
@ -0,0 +1,11 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
message = input("Введите сообщение: ")
|
||||
client.sendto(message.encode(), ("127.0.0.1", 10011))
|
||||
|
||||
data, _ = client.recvfrom(1024)
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
|
||||
client.close()
|
||||
14
udp_server.py
Normal file
14
udp_server.py
Normal file
@ -0,0 +1,14 @@
|
||||
import socket
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
server.bind(("0.0.0.0", 10011))
|
||||
|
||||
print("UDP сервер запущен")
|
||||
|
||||
while True:
|
||||
data, addr = server.recvfrom(1024)
|
||||
message = data.decode()
|
||||
print(f"Сообщение от {addr}: {message}")
|
||||
|
||||
response = f"[UDP] {message[::-1]}"
|
||||
server.sendto(response.encode(), addr)
|
||||
Loading…
Reference in New Issue
Block a user