Compare commits
10 Commits
3f0e365aa3
...
bda530a669
| Author | SHA1 | Date | |
|---|---|---|---|
| bda530a669 | |||
| b1c72ec4e7 | |||
| 010d5a0e77 | |||
| 4cda472d33 | |||
| c9b846daf4 | |||
| 93f5d681df | |||
| 1c7cc80c4d | |||
| 85bf2ed248 | |||
| 48f09e9b71 | |||
| e0eb1450e7 |
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
BIN
pictures/захват трафика tcp-сервера и клиента.png
Normal file
BIN
pictures/захват трафика tcp-сервера и клиента.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 98 KiB |
BIN
pictures/последовательность завершения соединения (FIN).png
Normal file
BIN
pictures/последовательность завершения соединения (FIN).png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 97 KiB |
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()
|
||||||
27
tcp_client_vgu.py
Normal file
27
tcp_client_vgu.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(('vyatsu.ru', 80))
|
||||||
|
|
||||||
|
# HTTP запрос КАК В REQUESTS (с полными заголовками)
|
||||||
|
request = (
|
||||||
|
"GET / HTTP/1.1\r\n"
|
||||||
|
"Host: vyatsu.ru\r\n"
|
||||||
|
"User-Agent: python-requests/2.33.1\r\n"
|
||||||
|
"Accept-Encoding: gzip, deflate\r\n"
|
||||||
|
"Accept: */*\r\n"
|
||||||
|
"Connection: keep-alive\r\n"
|
||||||
|
"\r\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
print("ЗАПРОС (как в requests):")
|
||||||
|
print(request)
|
||||||
|
|
||||||
|
# Отправляем запрос
|
||||||
|
client.sendall(request.encode())
|
||||||
|
|
||||||
|
response = client.recv(4096)
|
||||||
|
print("\nОТВЕТ:")
|
||||||
|
print(response.decode())
|
||||||
|
|
||||||
|
client.close()
|
||||||
21
tcp_server.py
Normal file
21
tcp_server.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
server.bind(("0.0.0.0", 10000))
|
||||||
|
server.listen(1)
|
||||||
|
print("TCP сервер запущен")
|
||||||
|
|
||||||
|
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':
|
||||||
|
break
|
||||||
10
token_read.py
Normal file
10
token_read.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
f = open("tokens.txt", 'r+')
|
||||||
|
for i in f:
|
||||||
|
if "readtok" in i:
|
||||||
|
for j in i:
|
||||||
|
TOKEN = i[i.index('-') + 2: -1]
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||||
|
print(response.json())
|
||||||
42
token_write.py
Normal file
42
token_write.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import requests
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append(r"C:\Users\Максим\Desktop\доки по вузу\2_курс\практика_2\2 задание\venv\Lib\site-packages")
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
TOKEN = os.getenv('writetok')
|
||||||
|
|
||||||
|
if not TOKEN:
|
||||||
|
print("Токен не найден!")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"token {TOKEN}",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_data = {
|
||||||
|
"name": "Repo_lab3_make_with_api",
|
||||||
|
"description": "Репозиторий создан через API Gitea",
|
||||||
|
"private": False,
|
||||||
|
"auto_init": True
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Создание репозитория...")
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
"https://git.vyatsu.ru/api/v1/user/repos",
|
||||||
|
headers=headers,
|
||||||
|
json=repo_data
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.status_code == 201:
|
||||||
|
repo = response.json()
|
||||||
|
print(f"Репозиторий создан!")
|
||||||
|
print(f"Название: {repo['full_name']}")
|
||||||
|
print(f"URL: {repo['html_url']}")
|
||||||
|
else:
|
||||||
|
print(f"Ошибка: {response.status_code}")
|
||||||
|
print(response.text)
|
||||||
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', 10002))
|
||||||
|
data, _ = client.recvfrom(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
client.close()
|
||||||
21
udp_server.py
Normal file
21
udp_server.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import socket
|
||||||
|
import time
|
||||||
|
|
||||||
|
counter = 0
|
||||||
|
total_bytes = 0
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
server.bind(('0.0.0.0', 10002))
|
||||||
|
print("UDP сервер запущен (со статистикой)")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data, addr = server.recvfrom(1024)
|
||||||
|
counter += 1
|
||||||
|
total_bytes += len(data)
|
||||||
|
|
||||||
|
original = data.decode()
|
||||||
|
|
||||||
|
modified = f"[#{counter}] [байт:{len(data)}] [всего:{total_bytes}] {original.upper()}"
|
||||||
|
|
||||||
|
print(f"Пакет #{counter} от {addr}: {original} -> {modified}")
|
||||||
|
server.sendto(modified.encode(), addr)
|
||||||
Loading…
Reference in New Issue
Block a user