From 5f2d5fc62d97d63f9e2a4f2d1fd3f83318196a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=D0=BE=D0=B2=20=D0=98=D0=BB=D1=8C?= =?UTF-8?q?=D1=8F=20=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Wed, 30 Apr 2025 22:22:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=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=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ .ipynb_checkpoints/README-checkpoint.md | 1 + Practika2 | 1 + tcp_client.py | 7 +++++++ tcp_client2.py | 9 +++++++++ tcp_client3.py | 4 ++++ tcp_client4.py | 10 ++++++++++ tcp_client5.py | 16 ++++++++++++++++ tcp_server.py | 10 ++++++++++ 9 files changed, 60 insertions(+) create mode 100644 .ipynb_checkpoints/README-checkpoint.md create mode 160000 Practika2 create mode 100644 tcp_client.py create mode 100644 tcp_client2.py create mode 100644 tcp_client3.py create mode 100644 tcp_client4.py create mode 100644 tcp_client5.py create mode 100644 tcp_server.py diff --git a/.gitignore b/.gitignore index c18dd8d..b110439 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +venv/ +.env __pycache__/ diff --git a/.ipynb_checkpoints/README-checkpoint.md b/.ipynb_checkpoints/README-checkpoint.md new file mode 100644 index 0000000..4efd0e0 --- /dev/null +++ b/.ipynb_checkpoints/README-checkpoint.md @@ -0,0 +1 @@ +ewe diff --git a/Practika2 b/Practika2 new file mode 160000 index 0000000..6c0d012 --- /dev/null +++ b/Practika2 @@ -0,0 +1 @@ +Subproject commit 6c0d01285536b781470abf7e141831514f8c182f diff --git a/tcp_client.py b/tcp_client.py new file mode 100644 index 0000000..75cd478 --- /dev/null +++ b/tcp_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 diff --git a/tcp_client2.py b/tcp_client2.py new file mode 100644 index 0000000..4c1fa7e --- /dev/null +++ b/tcp_client2.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/tcp_client3.py b/tcp_client3.py new file mode 100644 index 0000000..83588ae --- /dev/null +++ b/tcp_client3.py @@ -0,0 +1,4 @@ +import requests + +response = requests.get("http://vyatsu.ru") +print(response.text[:500]) \ No newline at end of file diff --git a/tcp_client4.py b/tcp_client4.py new file mode 100644 index 0000000..8b71f39 --- /dev/null +++ b/tcp_client4.py @@ -0,0 +1,10 @@ +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()) \ No newline at end of file diff --git a/tcp_client5.py b/tcp_client5.py new file mode 100644 index 0000000..f8b843a --- /dev/null +++ b/tcp_client5.py @@ -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": "praktica3rabotaAPI", + "private": False, + "description": "Создание репозитория, созданный с помощью API" +} + +response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", headers=headers, json=data) +print(response.json()) \ No newline at end of file diff --git a/tcp_server.py b/tcp_server.py new file mode 100644 index 0000000..39ce695 --- /dev/null +++ b/tcp_server.py @@ -0,0 +1,10 @@ +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(data.upper(), addr) \ No newline at end of file