Skip to content

Instantly share code, notes, and snippets.

@klynch
Created September 23, 2013 19:17
Show Gist options
  • Save klynch/6675465 to your computer and use it in GitHub Desktop.
Save klynch/6675465 to your computer and use it in GitHub Desktop.
import socket
def netcat(hostname, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, port))
s.sendall(content)
s.shutdown(socket.SHUT_WR)
while 1:
data = s.recv(1024)
if data == "":
break
print "Received:", repr(data)
print "Connection closed."
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment