Skip to content

Instantly share code, notes, and snippets.

@jeffgeiger
Forked from echojc/listen.py
Created September 1, 2020 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffgeiger/0b9d1f9c62e9647fed7bbdca18e4ada1 to your computer and use it in GitHub Desktop.
Save jeffgeiger/0b9d1f9c62e9647fed7bbdca18e4ada1 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment