Created
May 23, 2013 03:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
Use
print('%d: connection from %s' % (len(l), a))
for newer Python