Compare commits

...

No commits in common. "master" and "main" have entirely different histories.
master ... main

11 changed files with 2 additions and 166 deletions

9
.gitignore vendored
View File

@ -1,9 +0,0 @@
venv/
.env/
__pycache__/
*.pyc
.vscode/
.idea/
*.log
api_git_example.py
token.py

View File

@ -1,32 +1,3 @@
\# Учебная практика №2.3 — Работа с сетевыми соединениями в Python
Репозиторий содержит решение ЛР3: примеры работы с сетевыми протоколами TCP и UDP,
HTTP-запросами и анализом трафика в Wireshark, а также примеры обращения к API Gitea
с использованием токенов доступа.
\## Содержание
\- `tcp\_server.py`, `tcp\_client.py` — обмен данными по TCP
\- `udp\_server.py`, `udp\_client.py` — обмен данными по UDP
\- `http\_socket\_client.py` — HTTP-запрос к `vyatsu.ru` через модуль `socket`
\- `requests\_example.py` — HTTP-запрос к `vyatsu.ru` через библиотеку `requests`
\- `gitea\_read\_user.py` — запрос к API Gitea `/api/v1/user` с токеном только на чтение
\- `gitea\_create\_repo.py` — пример обращения к API Gitea с токеном на запись
\- `.gitignore` — файлы и каталоги, которые не добавляются в репозиторий
\- `README.md` — краткое описание работы
# lab3-api-repo
Репозиторий создан через Gitea API

View File

@ -1,6 +0,0 @@
import requests
TOKEN = "GIT_VYATSU_TOKEN1"
headers = {"Authorization": f"token {TOKEN}"}
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
print(response.json())

View File

@ -1,19 +0,0 @@
import os
import requests
TOKEN = os.getenv("GITEA_WRITE_TOKEN")
headers = {
"Authorization": f"token {TOKEN}",
"Content-Type": "application/json"
}
data = {
"name": "lab3-api-repo",
"description": "Репозиторий создан через Gitea API",
"private": False,
"auto_init": True
}
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", json=data, headers=headers)
print(response.status_code)
print(response.json())

View File

@ -1,13 +0,0 @@
import os
import requests
TOKEN = os.getenv("GITEA_READ_TOKEN")
if not TOKEN:
raise RuntimeError("Переменная окружения GITEA_READ_TOKEN не задана")
headers = {"Authorization": f"token {TOKEN}"}
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
print(response.status_code)
print(response.text)

View File

@ -1,17 +0,0 @@
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"
"Connection: close\r\n"
"\r\n"
)
client.sendall(request.encode("utf-8"))
response = client.recv(4096)
print(response.decode(errors="ignore"))
client.close()

View File

@ -1,4 +0,0 @@
import requests
response = requests.get("http://vyatsu.ru")
print(response.text[:500])

View File

@ -1,12 +0,0 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(("127.0.0.1", 12000))
message = "hello server"
client.sendall(message.encode())
data = client.recv(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

View File

@ -1,30 +0,0 @@
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("0.0.0.0", 12000))
server.listen(1)
print("TCP сервер запущен и ожидает подключения...")
while True:
conn, addr = server.accept()
print(f"Подключение от {addr}")
data = conn.recv(1024)
if not data:
conn.close()
continue
message = data.decode()
print(f"Получено сообщение: {message}")
response = message.upper()
conn.sendall(response.encode())
conn.close()
if response == "EXIT":
print("Сервер завершает работу")
break
server.close()

View File

@ -1,11 +0,0 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
message = "привет сервер"
client.sendto(message.encode(), ("127.0.0.1", 10001))
data, _ = client.recvfrom(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

View File

@ -1,14 +0,0 @@
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind(("0.0.0.0", 10001))
print("UDP сервер запущен и ожидает сообщения...")
while True:
data, addr = server.recvfrom(1024)
message = data.decode()
print(f"Сообщение от {addr}: {message}")
response = message.upper()
server.sendto(response.encode(), addr)