Work is done, 2 zadanie gotovo
This commit is contained in:
parent
c868f8a076
commit
41612009a0
5
.gitignore
vendored
5
.gitignore
vendored
@ -0,0 +1,5 @@
|
|||||||
|
venv/
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.env
|
||||||
|
.vscode/
|
||||||
6
GitAPI.py
Normal file
6
GitAPI.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
TOKEN = "27f359e8d73918297d6276b4a0c11237f38ac71e"
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||||
|
print(response.json())
|
||||||
21
GitAPIWrite.py
Normal file
21
GitAPIWrite.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
TOKEN = os.getenv("GITEA_WRITE_TOKEN")
|
||||||
|
|
||||||
|
headers = {"Authorization": f"token {TOKEN}", "Content-Type": "application/json"}
|
||||||
|
repo_name = "lab3-test-repo-ivanov" # Замените на свою фамилию
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"name": repo_name,
|
||||||
|
"description": "Создано через API для лабораторной работы 3",
|
||||||
|
"private": True
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", headers=headers, json=data)
|
||||||
|
if response.status_code == 201:
|
||||||
|
print(f"Репозиторий '{repo_name}' успешно создан!")
|
||||||
|
else:
|
||||||
|
print(f"Ошибка: {response.json()}")
|
||||||
4
http_request.py
Normal file
4
http_request.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
||||||
17
http_socket.py
Normal file
17
http_socket.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
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: keep-alive\r\n\r\n"
|
||||||
|
)
|
||||||
|
client.sendall(request.encode())
|
||||||
|
response = client.recv(4096)
|
||||||
|
print(response.decode())
|
||||||
|
client.close()
|
||||||
8
tcp_client.py
Normal file
8
tcp_client.py
Normal file
@ -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'exit')
|
||||||
|
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 сервер запущен на порту 10000")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
conn, addr = server.accept()
|
||||||
|
print(f"Подключение от {addr}")
|
||||||
|
data = conn.recv(1024)
|
||||||
|
if not data:
|
||||||
|
conn.close()
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f"Получено: {data.decode()}")
|
||||||
|
response = data.upper()
|
||||||
|
conn.sendall(response)
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if data.upper() == b'EXIT':
|
||||||
|
print("Получена команда EXIT, сервер завершает работу.")
|
||||||
|
break
|
||||||
|
|
||||||
|
server.close()
|
||||||
7
udp_client.py
Normal file
7
udp_client.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
client.sendto(b'hello server', ('127.0.0.1', 10102))
|
||||||
|
data, _ = client.recvfrom(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
client.close()
|
||||||
10
udp_server.py
Normal file
10
udp_server.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
server.bind(('0.0.0.0', 10102))
|
||||||
|
print("UDP сервер запущен")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data, addr = server.recvfrom(1024)
|
||||||
|
print(f"Сообщение от {addr}: {data.decode()}")
|
||||||
|
server.sendto(data[::-1], addr)
|
||||||
Loading…
Reference in New Issue
Block a user