выполнил задание 2 учебной практики
This commit is contained in:
commit
8f48788505
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
venv/
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.env
|
||||||
|
.vscode/
|
||||||
|
*.code-workspace
|
||||||
|
*.log
|
||||||
38
gitea_api.py
Normal file
38
gitea_api.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
TOKEN = os.getenv("GITEA_TOKEN")
|
||||||
|
|
||||||
|
if not TOKEN:
|
||||||
|
print("Ошибка: GITEA_TOKEN не найден в файле .env")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
|
||||||
|
print("Чтение информации о пользователе")
|
||||||
|
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||||
|
|
||||||
|
print(f"Статус код: {response.status_code}")
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
user = response.json()
|
||||||
|
print(f"Логин: {user.get('login')}")
|
||||||
|
print(f"Email: {user.get('email')}")
|
||||||
|
else:
|
||||||
|
print(f"Ошибка: {response.text}")
|
||||||
|
|
||||||
|
print("\nСоздание репозитория")
|
||||||
|
repo_data = {"name": "network-lab-3", "private": False}
|
||||||
|
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", headers=headers, json=repo_data)
|
||||||
|
|
||||||
|
print(f"Статус код: {response.status_code}")
|
||||||
|
|
||||||
|
if response.status_code == 201:
|
||||||
|
print(f"Репозиторий создан: {response.json().get('html_url')}")
|
||||||
|
elif response.status_code == 422:
|
||||||
|
print("Репозиторий уже существует")
|
||||||
|
else:
|
||||||
|
print(f"Ошибка: {response.text}")
|
||||||
5
http_requests.py
Normal file
5
http_requests.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.status_code)
|
||||||
|
print(response.text[:500])
|
||||||
11
http_socket.py
Normal file
11
http_socket.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
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()
|
||||||
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('utf-8'))
|
||||||
|
|
||||||
|
data = client.recv(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode('utf-8')}")
|
||||||
|
|
||||||
|
client.close()
|
||||||
28
tcp_server.py
Normal file
28
tcp_server.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
server.bind(("0.0.0.0", 10000))
|
||||||
|
server.listen(1)
|
||||||
|
print("TCP сервер запущен на порту 10000")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
conn, addr = server.accept()
|
||||||
|
print(f"Подключение от {addr}")
|
||||||
|
|
||||||
|
data = conn.recv(1024)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
|
||||||
|
received_text = data.decode('utf-8')
|
||||||
|
print(f"Получено: {received_text}")
|
||||||
|
|
||||||
|
response_text = received_text.upper()
|
||||||
|
conn.sendall(response_text.encode('utf-8'))
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if response_text == 'EXIT':
|
||||||
|
print("Завершаем сервер")
|
||||||
|
break
|
||||||
|
|
||||||
|
server.close()
|
||||||
10
udp_client.py
Normal file
10
udp_client.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
|
||||||
|
message = input("Введите сообщение: ")
|
||||||
|
client.sendto(message.encode(), ('127.0.0.1', 10001))
|
||||||
|
|
||||||
|
data, addr = client.recvfrom(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
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', 10001))
|
||||||
|
print("UDP сервер запущен на порту 10001")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data, addr = server.recvfrom(1024)
|
||||||
|
print(f"Сообщение от {addr}: {data.decode()}")
|
||||||
|
|
||||||
|
modified = data.decode()[::-1].encode()
|
||||||
|
server.sendto(modified, addr)
|
||||||
Loading…
Reference in New Issue
Block a user