Проект готов
This commit is contained in:
parent
7e64b9d0bd
commit
f7ed750159
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,3 @@
|
||||
.venv/
|
||||
.venv/
|
||||
.env
|
||||
*.png
|
9
api.py
Normal file
9
api.py
Normal file
@ -0,0 +1,9 @@
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
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.json())
|
4
http_req.py
Normal file
4
http_req.py
Normal file
@ -0,0 +1,4 @@
|
||||
import requests
|
||||
|
||||
response = requests.get("http://vyatsu.ru")
|
||||
print(response.text[:500])
|
9
http_socket.py
Normal file
9
http_socket.py
Normal file
@ -0,0 +1,9 @@
|
||||
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\n\r\n"
|
||||
client.sendall(request.encode())
|
||||
response = client.recv(4096)
|
||||
print(response.decode())
|
||||
client.close()
|
8
tcpc.py
Normal file
8
tcpc.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'hello server')
|
||||
data = client.recv(1024)
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
client.close()
|
8
tcpc_upd.py
Normal file
8
tcpc_upd.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()
|
21
tcps.py
Normal file
21
tcps.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
|
7
udpc.py
Normal file
7
udpc.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()
|
10
udps.py
Normal file
10
udps.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 сервер запущен")
|
||||
|
||||
while True:
|
||||
data, addr = server.recvfrom(1024)
|
||||
print(f"Сообщение от {addr}: {data.decode()}")
|
||||
server.sendto(data.upper(), addr)
|
15
udps_upd.py
Normal file
15
udps_upd.py
Normal file
@ -0,0 +1,15 @@
|
||||
import socket
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
server.bind(('0.0.0.0', 10002))
|
||||
|
||||
print("UDP сервер запущен на порту 10002")
|
||||
|
||||
while True:
|
||||
data, addr = server.recvfrom(1024)
|
||||
print(f"Сообщение от {addr}: {data.decode()}")
|
||||
|
||||
modified_data = f"[MODIFIED] {data.decode().upper()} [END]"
|
||||
|
||||
server.sendto(modified_data.encode(), addr)
|
Loading…
Reference in New Issue
Block a user