Лабораторная работа 3 готова
This commit is contained in:
parent
904d8595fa
commit
1b49b733a1
3
.gitignore
vendored
3
.gitignore
vendored
@ -18,4 +18,5 @@ token.txt
|
||||
# Временные файлы
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*.swp
|
||||
.env
|
||||
28
create_repo.py
Normal file
28
create_repo.py
Normal file
@ -0,0 +1,28 @@
|
||||
import os
|
||||
import requests
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv("TOKEN")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"token {TOKEN}"
|
||||
}
|
||||
|
||||
data = {
|
||||
"name": "lab3-api-test"
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
"https://git.vyatsu.ru/api/v1/user/repos",
|
||||
headers=headers,
|
||||
json=data
|
||||
)
|
||||
|
||||
print("Статус:", response.status_code)
|
||||
|
||||
print(response.json())
|
||||
|
||||
input()
|
||||
23
gitea_api.py
Normal file
23
gitea_api.py
Normal file
@ -0,0 +1,23 @@
|
||||
import os
|
||||
import requests
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv("TOKEN")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"token {TOKEN}"
|
||||
}
|
||||
|
||||
response = requests.get(
|
||||
"https://git.vyatsu.ru/api/v1/user",
|
||||
headers=headers
|
||||
)
|
||||
|
||||
print("Статус:", response.status_code)
|
||||
|
||||
print(response.json())
|
||||
|
||||
input("\nНажми Enter...")
|
||||
41
http_requests.py
Normal file
41
http_requests.py
Normal file
@ -0,0 +1,41 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
print("Подключение к серверу...")
|
||||
|
||||
client.connect(("vyatsu.ru", 80))
|
||||
|
||||
request = (
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"Host: vyatsu.ru\r\n"
|
||||
"User-Agent: Mozilla/5.0\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n"
|
||||
)
|
||||
|
||||
print("Отправка запроса...\n")
|
||||
|
||||
client.sendall(request.encode())
|
||||
|
||||
response = b""
|
||||
|
||||
running = True
|
||||
|
||||
while running:
|
||||
|
||||
data = client.recv(4096)
|
||||
|
||||
if data:
|
||||
response += data
|
||||
else:
|
||||
running = False
|
||||
|
||||
decoded = response.decode(errors="ignore")
|
||||
|
||||
print(decoded[:5000])
|
||||
|
||||
client.close()
|
||||
|
||||
input("\nНажми Enter...")
|
||||
26
http_socket.py
Normal file
26
http_socket.py
Normal file
@ -0,0 +1,26 @@
|
||||
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.32.3\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(errors="ignore"))
|
||||
|
||||
client.close()
|
||||
@ -0,0 +1,15 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
client.connect(("127.0.0.1", 10000))
|
||||
|
||||
message = input("Введите сообщение: ")
|
||||
|
||||
client.sendall(message.encode())
|
||||
|
||||
data = client.recv(1024)
|
||||
|
||||
print(f"Ответ сервера: {data.decode()}")
|
||||
|
||||
client.close()
|
||||
@ -0,0 +1,34 @@
|
||||
import socket
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
server.bind(("0.0.0.0", 10000))
|
||||
|
||||
server.listen(1)
|
||||
|
||||
print("TCP сервер запущен")
|
||||
|
||||
running = True
|
||||
|
||||
while running:
|
||||
|
||||
conn, addr = server.accept()
|
||||
|
||||
print(f"Подключение от {addr}")
|
||||
|
||||
data = conn.recv(1024)
|
||||
|
||||
if data:
|
||||
|
||||
text = data.decode()
|
||||
|
||||
print(f"Получено: {text}")
|
||||
|
||||
conn.sendall(data.upper())
|
||||
|
||||
if text.upper() == "EXIT":
|
||||
running = False
|
||||
|
||||
conn.close()
|
||||
|
||||
server.close()
|
||||
@ -0,0 +1,20 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
running = True
|
||||
|
||||
while running:
|
||||
|
||||
message = input("Введите сообщение: ")
|
||||
|
||||
client.sendto(message.encode(), ("127.0.0.1", 12000))
|
||||
|
||||
data, _ = client.recvfrom(1024)
|
||||
|
||||
print(f"Ответ сервера: {data.decode()}")
|
||||
|
||||
if message.upper() == "EXIT":
|
||||
running = False
|
||||
|
||||
client.close()
|
||||
@ -0,0 +1,26 @@
|
||||
import socket
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
server.bind(("0.0.0.0", 12000))
|
||||
|
||||
print("UDP сервер запущен")
|
||||
|
||||
running = True
|
||||
|
||||
while running:
|
||||
|
||||
data, addr = server.recvfrom(1024)
|
||||
|
||||
text = data.decode()
|
||||
|
||||
print(f"Сообщение от {addr}: {text}")
|
||||
|
||||
response = "СЕРВЕР: " + text[::-1]
|
||||
|
||||
server.sendto(response.encode(), addr)
|
||||
|
||||
if text.upper() == "EXIT":
|
||||
running = False
|
||||
|
||||
server.close()
|
||||
Loading…
Reference in New Issue
Block a user