Skip to content

Instantly share code, notes, and snippets.

@echojc
Created May 23, 2013 03:58
Show Gist options
  • Save echojc/5632656 to your computer and use it in GitHub Desktop.
Save echojc/5632656 to your computer and use it in GitHub Desktop.
Quick 'n' dirty Python script to listen on a port and do nothing with the connection, simulating a server that allows you to connect but does not reply.
#!/usr/bin/python
import socket
import sys
if (len(sys.argv) != 2 or not sys.argv[1].isdigit()):
print 'Usage: listen <port>',
exit()
p = int(sys.argv[1])
l = []
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', p))
s.listen(1)
while 1:
(c, a) = s.accept()
l.append(c)
print '%d: connection from %s' % (len(l), a)
@williamdes
Copy link

Use print('%d: connection from %s' % (len(l), a)) for newer Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment