mirror of
https://github.com/Justuser3310/jetwork.git
synced 2025-01-19 01:18:48 +00:00
Передача данных теперь точно работает
This commit is contained in:
parent
9b032e48f2
commit
3e853ddb79
25
main.py
25
main.py
@ -1,8 +1,9 @@
|
||||
from os import system, name
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
|
||||
# Здесь общий запуск всех файлов и команд
|
||||
|
||||
'''
|
||||
# Проверка обновлений
|
||||
from sys import argv
|
||||
if len(argv) == 1:
|
||||
@ -12,29 +13,29 @@ if len(argv) == 1:
|
||||
system("python main.py updated")
|
||||
exit()
|
||||
print("\nУспешно перезагружено!")
|
||||
|
||||
'''
|
||||
|
||||
# Порт для приёма всяких запросов
|
||||
from random import randint
|
||||
dest = randint(4000, 4200)
|
||||
def reverse_proxy():
|
||||
global dest
|
||||
port = 8000
|
||||
if name == "posix":
|
||||
system(f"./bore local {port} --to jetwork.404.mn")
|
||||
system(f"./bore local {port} --to jetwork.404.mn --port {dest}")
|
||||
elif name == "nt":
|
||||
system("")
|
||||
system(f"bore.exe local {port} --to jetwork.404.mn --port {dest}")
|
||||
|
||||
'''
|
||||
# Стартуем проброс порта
|
||||
rp = Thread(target = reverse_proxy)
|
||||
rp.start()
|
||||
sleep(0.5)
|
||||
'''
|
||||
print(f"\nВаш порт: {dest}")
|
||||
|
||||
'''
|
||||
from network import *
|
||||
|
||||
#server(8000)
|
||||
|
||||
if client(8001):
|
||||
print(1)
|
||||
else:
|
||||
print(2)
|
||||
'''
|
||||
#server(8001)
|
||||
client(8001)
|
||||
|
||||
|
56
network.py
56
network.py
@ -5,11 +5,35 @@ import os
|
||||
|
||||
# TODO:
|
||||
# 1. [+] Пинг
|
||||
# 2. [+] Проверка существования .zip сайта
|
||||
# 2. [+] Проверка существования сайта
|
||||
# 3. Передача сайта
|
||||
# 4. Приём рассылки сайтов
|
||||
|
||||
def server(port):
|
||||
def server(port = 8000):
|
||||
host = "127.0.0.1"
|
||||
|
||||
s = socket.socket()
|
||||
s.bind((host, port))
|
||||
|
||||
while True:
|
||||
s.listen(2)
|
||||
conn, address = s.accept()
|
||||
|
||||
print("Connection from: " + str(address))
|
||||
|
||||
while True:
|
||||
try:
|
||||
op = conn.recv(1024).decode()
|
||||
except:
|
||||
pass
|
||||
if not op:
|
||||
break
|
||||
|
||||
if op == "ping":
|
||||
conn.send("Pinged success".encode())
|
||||
conn.close()
|
||||
|
||||
'''
|
||||
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||
sock.bind (('127.0.0.1', port))
|
||||
|
||||
@ -18,6 +42,7 @@ def server(port):
|
||||
#print (addres[0], addres[1])
|
||||
op = data.decode('utf-8')
|
||||
|
||||
print(op)
|
||||
if op == "ping":
|
||||
sock.sendto("Pinged success".encode('utf-8'), addres)
|
||||
elif op[:3] == "is_":
|
||||
@ -28,20 +53,33 @@ def server(port):
|
||||
sock.sendto("not exist".encode('utf-8'), addres)
|
||||
else:
|
||||
sock.sendto(data, addres)
|
||||
|
||||
'''
|
||||
|
||||
# op = operation
|
||||
def client(dest_port, op = "ping"):
|
||||
server = '127.0.0.1', dest_port
|
||||
def client(port, op = "ping"):
|
||||
host = 'jetwork.404.mn'
|
||||
s = socket.socket()
|
||||
s.connect((host, port))
|
||||
|
||||
s.send("ping".encode())
|
||||
data = s.recv(1024).decode()
|
||||
print('Received from server: ' + data)
|
||||
|
||||
s.close()
|
||||
|
||||
'''
|
||||
server = 'jetwork.404.mn', port
|
||||
|
||||
sor = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||
sor.sendto((op).encode('utf-8'), server)
|
||||
sor.settimeout(5)
|
||||
|
||||
try:
|
||||
# try:
|
||||
if True:
|
||||
data = sor.recv(1024)
|
||||
res = data.decode('utf-8')
|
||||
return res
|
||||
except:
|
||||
print(f"[:{dest_port}] Недоступен.")
|
||||
return None
|
||||
# except:
|
||||
# print(f"[:{dest_port}] Недоступен.")
|
||||
# return None
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user