From 4824d1b648aba60eda46a11173eb025dc6fc8f71 Mon Sep 17 00:00:00 2001 From: stud203789 Date: Tue, 5 May 2026 16:50:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- practic03/.idea/.gitignore | 5 ++ .../inspectionProfiles/profiles_settings.xml | 6 ++ practic03/.idea/misc.xml | 7 +++ practic03/.idea/modules.xml | 8 +++ practic03/gitea_api.py | 55 +++++++++++++++++++ practic03/http_requests.py | 5 ++ practic03/http_socket.py | 9 +++ practic03/tcp_client.py | 8 +++ practic03/tcp_server.py | 21 +++++++ practic03/udp_cerver.py | 10 ++++ practic03/udp_client.py | 7 +++ 11 files changed, 141 insertions(+) create mode 100644 practic03/.idea/.gitignore create mode 100644 practic03/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 practic03/.idea/misc.xml create mode 100644 practic03/.idea/modules.xml create mode 100644 practic03/gitea_api.py create mode 100644 practic03/http_requests.py create mode 100644 practic03/http_socket.py create mode 100644 practic03/tcp_client.py create mode 100644 practic03/tcp_server.py create mode 100644 practic03/udp_cerver.py create mode 100644 practic03/udp_client.py diff --git a/practic03/.idea/.gitignore b/practic03/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/practic03/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/practic03/.idea/inspectionProfiles/profiles_settings.xml b/practic03/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/practic03/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/practic03/.idea/misc.xml b/practic03/.idea/misc.xml new file mode 100644 index 0000000..b5d2e7b --- /dev/null +++ b/practic03/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/practic03/.idea/modules.xml b/practic03/.idea/modules.xml new file mode 100644 index 0000000..a2e0c61 --- /dev/null +++ b/practic03/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/practic03/gitea_api.py b/practic03/gitea_api.py new file mode 100644 index 0000000..1ef31cc --- /dev/null +++ b/practic03/gitea_api.py @@ -0,0 +1,55 @@ +import os +import requests +from dotenv import load_dotenv + +# 1. Загружаем токен из файла .env +load_dotenv() +TOKEN = os.getenv("GITEA_TOKEN") + +if not TOKEN: + print(" Ошибка: Токен не найден! Проверь файл .env") + exit() + +# Заголовки для авторизации (стандарт Gitea) +headers = { + "Authorization": f"token {TOKEN}", + "Content-Type": "application/json" +} + + +def check_user(): + print("--- Шаг 1: Проверка профиля ---") + url = "https://git.vyatsu.ru/api/v1/user" + response = requests.get(url, headers=headers) + + if response.status_code == 200: + data = response.json() + print(f" Успешный вход! Логин: {data.get('login')}") + else: + print(f" Ошибка авторизации: {response.status_code}") + + +def create_repo(repo_name): + print(f"\n--- Шаг 2: Создание репозитория '{repo_name}' ---") + url = "https://git.vyatsu.ru/api/v1/user/repos" + payload = { + "name": repo_name, + "description": "Лабораторная работа по сетям", + "private": False, + "auto_init": True # Создаст сразу README.md + } + + response = requests.post(url, headers=headers, json=payload) + + if response.status_code == 201: + print(f" Репозиторий создан: {response.json().get('html_url')}") + elif response.status_code == 422: + print(" Репозиторий с таким именем уже существует.") + else: + print(f" Что-то пошло не так: {response.text}") + + +if __name__ == "__main__": + check_user() + # В названии репозитория укажи что-то уникальное, чтобы не пересекаться с другими + create_repo("NIMER3") diff --git a/practic03/http_requests.py b/practic03/http_requests.py new file mode 100644 index 0000000..5701c2f --- /dev/null +++ b/practic03/http_requests.py @@ -0,0 +1,5 @@ +import requests + +response = requests.get("http://vyatsu.ru") +print(response.status_code) +print(response.text[:500]) \ No newline at end of file diff --git a/practic03/http_socket.py b/practic03/http_socket.py new file mode 100644 index 0000000..4c1fa7e --- /dev/null +++ b/practic03/http_socket.py @@ -0,0 +1,9 @@ +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() \ No newline at end of file diff --git a/practic03/tcp_client.py b/practic03/tcp_client.py new file mode 100644 index 0000000..f42ec16 --- /dev/null +++ b/practic03/tcp_client.py @@ -0,0 +1,8 @@ +import socket + +client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +client.connect(('127.0.0.1', 10000)) +client.sendall(b'hello server11') +data = client.recv(1024) +print(f"Ответ от сервера: {data.decode()}") +client.close() diff --git a/practic03/tcp_server.py b/practic03/tcp_server.py new file mode 100644 index 0000000..8f14be6 --- /dev/null +++ b/practic03/tcp_server.py @@ -0,0 +1,21 @@ +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: + break + conn.sendall(data.upper()) + + conn.close() + + if data.upper() == b'EXIT': + break \ No newline at end of file diff --git a/practic03/udp_cerver.py b/practic03/udp_cerver.py new file mode 100644 index 0000000..eb4d6d0 --- /dev/null +++ b/practic03/udp_cerver.py @@ -0,0 +1,10 @@ +import socket + +server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +server.bind(('0.0.0.0', 10000)) +print("UDP сервер запущен") + +while True: + data, addr = server.recvfrom(1024) + print(f"Сообщение от {addr}: {data.decode()}") + server.sendto(data.upper(), addr) \ No newline at end of file diff --git a/practic03/udp_client.py b/practic03/udp_client.py new file mode 100644 index 0000000..75cd478 --- /dev/null +++ b/practic03/udp_client.py @@ -0,0 +1,7 @@ +import socket + +client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +client.sendto(b'hello server', ('127.0.0.1', 10001)) +data, _ = client.recvfrom(1024) +print(f"Ответ от сервера: {data.decode()}") +client.close() \ No newline at end of file