socket stuff
This commit is contained in:
@@ -2,6 +2,8 @@ from selenium import webdriver
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
url="https://patrickhlauke.github.io/recaptcha/"
|
||||
|
||||
@@ -28,7 +30,10 @@ def searchCaptcha(filename):
|
||||
|
||||
|
||||
def resolveCaptcha(url):
|
||||
driver=webdriver.Chrome('/Users/olivierpartensky/Programs/Library/Selenium/chromedriver')
|
||||
path = os.path.("/chromedriver")
|
||||
# dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
print(path)
|
||||
driver=webdriver.Chrome(path)
|
||||
action=webdriver.common.action_chains.ActionChains(driver)
|
||||
driver.get(url)
|
||||
#action.move_by_offset(36,156)
|
||||
|
||||
+30
-24
@@ -1,43 +1,46 @@
|
||||
import socket
|
||||
import select
|
||||
|
||||
HEADER_LENGTH=10
|
||||
IP="172.16.0.27."
|
||||
#IP="86.242.99.166"
|
||||
#IP='192.168.1.11'
|
||||
IP=socket.gethostname()
|
||||
IP=''
|
||||
HEADER_LENGTH = 10
|
||||
IP = "172.16.0.27."
|
||||
# IP="86.242.99.166"
|
||||
# IP='192.168.1.11'
|
||||
IP = socket.gethostname()
|
||||
IP = ''
|
||||
print(IP)
|
||||
PORT=1236
|
||||
PORT = 1236
|
||||
|
||||
|
||||
server_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
|
||||
server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
|
||||
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
|
||||
server_socket.bind((IP,PORT))
|
||||
server_socket.bind((IP, PORT))
|
||||
|
||||
server_socket.listen()
|
||||
|
||||
sockets_list=[server_socket]
|
||||
sockets_list = [server_socket]
|
||||
|
||||
clients = {}
|
||||
|
||||
clients={}
|
||||
|
||||
def receive_message(client_socket):
|
||||
try:
|
||||
message_header=client_socket.recv(HEADER_LENGTH)
|
||||
message_header = client_socket.recv(HEADER_LENGTH)
|
||||
if not len(message_header):
|
||||
return False
|
||||
else:
|
||||
message_length=int(message_header.decode("utf-8").strip())
|
||||
return {"header":message_header,"data":client_socket.recv(message_length)}
|
||||
message_length = int(message_header.decode("utf-8").strip())
|
||||
return {"header": message_header, "data": client_socket.recv(message_length)}
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
while True:
|
||||
read_sockets,_,exception_sockets=select.select(sockets_list,[],sockets_list)
|
||||
read_sockets, _, exception_sockets = select.select(
|
||||
sockets_list, [], sockets_list)
|
||||
for notified_socket in read_sockets:
|
||||
if notified_socket==server_socket:
|
||||
client_socket,client_address=server_socket
|
||||
if notified_socket == server_socket:
|
||||
client_socket, client_address = server_socket
|
||||
|
||||
user = receive_message(client_socket)
|
||||
if user is False:
|
||||
@@ -45,14 +48,15 @@ while True:
|
||||
|
||||
sockets_list.append(client_socket)
|
||||
|
||||
clients[client_socket]=user
|
||||
clients[client_socket] = user
|
||||
|
||||
print(f"Accepted new connection from {client_address[0]}:{client_address[1]} username: {user['data'].decode('utf-8')}")
|
||||
print(
|
||||
f"Accepted new connection from {client_address[0]}:{client_address[1]} username: {user['data'].decode('utf-8')}")
|
||||
|
||||
else:
|
||||
message=receive_message(notified_socket)
|
||||
message = receive_message(notified_socket)
|
||||
if message is False:
|
||||
m=clients[notified_socket]['data'].decode('utf-8')
|
||||
m = clients[notified_socket]['data'].decode('utf-8')
|
||||
print("Closed connection from {}".format(m))
|
||||
sockets_list.remove(notified_socket)
|
||||
del clients[notified_sockets]
|
||||
@@ -60,10 +64,12 @@ while True:
|
||||
|
||||
user = clients[notified_socket]
|
||||
|
||||
print(f"Received message from {user['data'].decode('utf-8')}: {message['data'].decode('utf-8')}")
|
||||
print(
|
||||
f"Received message from {user['data'].decode('utf-8')}: {message['data'].decode('utf-8')}")
|
||||
for client_socket in clients:
|
||||
if client_socket != notified_socket:
|
||||
client_socket.send(user['header']+user['data']+message['header']+message['data'])
|
||||
client_socket.send(
|
||||
user['header'] + user['data'] + message['header'] + message['data'])
|
||||
|
||||
for notified_socket in exception_sockets:
|
||||
sockets_list.remove(notified_socket)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import socket
|
||||
import time
|
||||
|
||||
|
||||
t0=time.time()
|
||||
duration=5
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
ip = '192.168.0.1'
|
||||
port = 1234
|
||||
s.connect((ip,port))
|
||||
|
||||
while time.time()-t0<duration:
|
||||
full_msg = ''
|
||||
while time.time()-t0<duration:
|
||||
print(time.time()-t0)
|
||||
msg = s.recv(8)
|
||||
if len(msg) <= 0:
|
||||
break
|
||||
full_msg += msg.decode("utf-8")
|
||||
|
||||
if len(full_msg) > 0:
|
||||
print(full_msg)
|
||||
@@ -0,0 +1,21 @@
|
||||
import socket
|
||||
|
||||
hote = "localhost"
|
||||
port = 12800
|
||||
|
||||
connexion_avec_serveur = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
connexion_avec_serveur.connect((hote, port))
|
||||
print("Connexion établie avec le serveur sur le port {}".format(port))
|
||||
|
||||
msg_a_envoyer = b""
|
||||
while msg_a_envoyer != b"fin":
|
||||
msg_a_envoyer = input("> ")
|
||||
# Peut planter si vous tapez des caractères spéciaux
|
||||
msg_a_envoyer = msg_a_envoyer.encode()
|
||||
# On envoie le message
|
||||
connexion_avec_serveur.send(msg_a_envoyer)
|
||||
msg_recu = connexion_avec_serveur.recv(1024)
|
||||
print(msg_recu.decode()) # Là encore, peut planter s'il y a des accents
|
||||
|
||||
print("Fermeture de la connexion")
|
||||
connexion_avec_serveur.close()
|
||||
@@ -0,0 +1,22 @@
|
||||
import socket
|
||||
import time
|
||||
|
||||
|
||||
t0=time.time()
|
||||
duration=5
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
ip = ''
|
||||
port = 1234
|
||||
s.bind((ip, port))
|
||||
s.listen(5)
|
||||
|
||||
while time.time()-t0<duration:
|
||||
# now our endpoint knows about the OTHER endpoint.
|
||||
clientsocket, address = s.accept()
|
||||
print(f"Connection from {address} has been established.")
|
||||
clientsocket.send(bytes("Hey there!!!", "utf-8"))
|
||||
clientsocket.close()
|
||||
|
||||
|
||||
print('server ended')
|
||||
@@ -0,0 +1,23 @@
|
||||
import socket
|
||||
|
||||
hote = ''
|
||||
port = 12800
|
||||
|
||||
connexion_principale = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
connexion_principale.bind((hote, port))
|
||||
connexion_principale.listen(5)
|
||||
print("Le serveur écoute à présent sur le port {}".format(port))
|
||||
|
||||
connexion_avec_client, infos_connexion = connexion_principale.accept()
|
||||
|
||||
msg_recu = b""
|
||||
while msg_recu != b"fin":
|
||||
msg_recu = connexion_avec_client.recv(1024)
|
||||
# L'instruction ci-dessous peut lever une exception si le message
|
||||
# Réceptionné comporte des accents
|
||||
print(msg_recu.decode())
|
||||
connexion_avec_client.send(b"5 / 5")
|
||||
|
||||
print("Fermeture de la connexion")
|
||||
connexion_avec_client.close()
|
||||
connexion_principale.close()
|
||||
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
|
||||
|
||||
from subprocess import call
|
||||
|
||||
|
||||
|
||||
os.system("echo slt")
|
||||
@@ -0,0 +1,17 @@
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
command = "open -a Terminal -n\n echo test"
|
||||
|
||||
ssh = subprocess.Popen(["ssh", "%s" % host, command],
|
||||
shell=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
result = ssh.stdout.readlines()
|
||||
|
||||
if result == []:
|
||||
error = ssh.stderr.readlines()
|
||||
print("ERROR: %s" % error )
|
||||
else:
|
||||
print( result )
|
||||
Reference in New Issue
Block a user