комментарий
This commit is contained in:
parent
25ca467309
commit
48d76bad44
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.venv/
|
||||
.idea/
|
||||
.idea/
|
||||
.env
|
||||
21
gitea_create_repo.py
Normal file
21
gitea_create_repo.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv("GITEA_TOKEN_WRITE")
|
||||
headers = {
|
||||
"Authorization": f"token {TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
data = {
|
||||
"name": "my-lab3-repo",
|
||||
"description": "Создано через API для лабораторной работы №3",
|
||||
"private": False
|
||||
}
|
||||
|
||||
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", headers=headers, json=data)
|
||||
print(f"Статус: {response.status_code}")
|
||||
print(response.json())
|
||||
12
gitea_read.py
Normal file
12
gitea_read.py
Normal file
@ -0,0 +1,12 @@
|
||||
import os
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv("GITEA_TOKEN_READ")
|
||||
headers = {"Authorization": f"token {TOKEN}"}
|
||||
|
||||
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||
print("Информация о пользователе:")
|
||||
print(response.json())
|
||||
4
http_requests.py
Normal file
4
http_requests.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\nHost: vyatsu.ru\r\nUser-Agent: python-requests/2.33.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n"
|
||||
|
||||
client.sendall(request.encode())
|
||||
response = b""
|
||||
while True:
|
||||
c = client.recv(4096)
|
||||
if not c:
|
||||
break
|
||||
response += c
|
||||
|
||||
print(response.decode())
|
||||
client.close()
|
||||
9
tcp_client.py
Normal file
9
tcp_client.py
Normal file
@ -0,0 +1,9 @@
|
||||
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()
|
||||
18
tcp_server.py
Normal file
18
tcp_server.py
Normal file
@ -0,0 +1,18 @@
|
||||
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:
|
||||
break
|
||||
conn.sendall(data.upper())
|
||||
conn.close()
|
||||
if data.upper() == b'EXIT':
|
||||
print("Сервер завершает работу")
|
||||
break
|
||||
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', 10001))
|
||||
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', 10001))
|
||||
print("UDP сервер запущен на порту 10001")
|
||||
|
||||
while True:
|
||||
data, addr = server.recvfrom(1024)
|
||||
print(f"Сообщение от {addr}: {data.decode()}")
|
||||
server.sendto(data.upper(), addr)
|
||||
Loading…
Reference in New Issue
Block a user