I have some basic knowledge of socket programming in Python. Up to now all I have been able to do when establishing a socket is sending a string to a client, what I would like to know is what else can be sent? For example could a program be tunnelled through from the host to the client - like the way netcat allows programs to be executed after a connection is established?
Here is code that only sends a string:
Here is code that only sends a string:
Code:
#!/usr/bin/python
import socket, sys
if len(sys.argv) < 3:
print 'Usage: %s [IP] [port]' % sys.argv[0]
sys.exit(1)
ip = sys.argv[1]
port = int(sys.argv[2])
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((ip, port))
sock.listen(1)
print "Waiting for someone."
request, client = sock.accept()
print "Received connection from", client
request.send('Some boring text..\n') #<-- can a program be sent instead of this?
request.shutdown(2)
print "Socket closed."
sock.close()
Comment