So I'm trying to make a telnet like application.
So far, I've established a connection between the server and the client app, and I've used the subprocess module to pass commands from the client (sent to the server) to bash.
Here's my server code -
Client code -
So the problem here, is that the client sends the cmd's to bash on the server, and the output appears on the server instead of the client.
So I need to send the output BACK to the client and print it.
When I tried to solve this issue, this is the code I ended up with -
Server -
Client -
This doesn't work either....
Any help?
Thanks!
khan
So far, I've established a connection between the server and the client app, and I've used the subprocess module to pass commands from the client (sent to the server) to bash.
Here's my server code -
Code:
#! /usr/bin/env python
import socket,sys,subprocess
HOST = ''
PORT = 335
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
while 1:
try:
conn, addr = s.accept()
data = conn.recv(1024)
a = data
b = a.split()
print ''
retcode = subprocess.call(b)
except sock.error:
s.close()
if a == "exit":
print "Client is disconnecting"
Client code -
Code:
#! /usr/bin/env python
import socket,sys
i = raw_input("IP: ")
p = 335
while 1:
try:
d = raw_input("Command: ")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((i, p))
s.send(d)
except socket.error:
print "Error"
break
So the problem here, is that the client sends the cmd's to bash on the server, and the output appears on the server instead of the client.
So I need to send the output BACK to the client and print it.
When I tried to solve this issue, this is the code I ended up with -
Server -
Code:
#! /usr/bin/env python
import socket,sys,subprocess
HOST = ''
PORT = 335
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
while 1:
conn, addr = s.accept()
data = conn.recv(1024)
a = data
b = a.split()
print ''
retcode = subprocess.call(b)
string = str(retcode)
s.send(string)
if a == "exit":
print "Client is disconnecting"
Client -
Code:
#! /usr/bin/env python
import socket,sys
i = raw_input("IP: ")
p = 335
while 1:
try:
d = raw_input("Command: ")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((i, p))
s.send(d)
conn, addr = s.accept()
output = conn.recv(1024)
prt = int(output)
print prt
except socket.error:
print "Error"
break
This doesn't work either....
Any help?
Thanks!
khan