Created
November 11, 2013 02:39
-
-
Save nairteashop/7406911 to your computer and use it in GitHub Desktop.
A simple python server that accepts connections on a given port and simply dumps all data it receives from a client that connects to that port.
This file contains hidden or 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 | |
# | |
# A simple python server that accepts connections on a given port and simply dumps | |
# all data it receives from a client that connects to that port. | |
# | |
# The listening port number can be provided as an argument; the default is 8080. | |
# | |
# Copyright (c) 2013 Arun Nair (http://nairteashop.org). | |
# Licensed under the MIT license. | |
# | |
import sys | |
from socket import * | |
port = 8080 | |
if len(sys.argv) > 1: | |
port = int( sys.argv[1] ) | |
s = socket( AF_INET, SOCK_STREAM ) | |
s.bind( ("",port) ) | |
s.listen(1) | |
print "Listening on port", port | |
c, addr = s.accept() | |
print "Client connected from", addr | |
print "Disconnect client to quit." | |
while True: | |
try: | |
data = c.recv(1024) | |
if not data: break | |
except KeyboardInterrupt: | |
pass | |
print ' '.join('0x%s' % c.encode('hex') for c in data) + '\t' + data | |
c.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment