diff --git a/lib/service/htmlcontent.py b/lib/service/htmlcontent.py index 2b3ce39..6d9580c 100644 --- a/lib/service/htmlcontent.py +++ b/lib/service/htmlcontent.py @@ -5,4 +5,6 @@ The htmlcontent service in pure Python. STUPID NAME!!! # http://pycurl.sourceforge.net/ --- seems old... # http://www.angryobjects.com/2011/10/15/http-with-python-pycurl-by-example/ # -# maybe better: http://docs.python.org/2/library/urllib.html \ No newline at end of file +# maybe better: http://docs.python.org/2/library/urllib.html +# +# or look at tcpconnect.py! could be useful to. \ No newline at end of file diff --git a/lib/service/tcpconnect.py b/lib/service/tcpconnect.py new file mode 100644 index 0000000..ba097b2 --- /dev/null +++ b/lib/service/tcpconnect.py @@ -0,0 +1,35 @@ +""" +The tcpconnect service in pure Python. +""" + +import socket +import sys + +HOST = 'linspector.org' +GET = '/index.html' +PORT = 80 + +try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +except socket.error, msg: + sys.stderr.write("[ERROR] %s\n" % msg[1]) + sys.exit(1) + +try: + sock.connect((HOST, PORT)) +except socket.error, msg: + sys.stderr.write("[ERROR] %s\n" % msg[1]) + sys.exit(2) + +sock.send("GET %s HTTP/1.0\r\nHost: %s\r\n\r\n" % (GET, HOST)) + +data = sock.recv(1024) +string = "" +while len(data): + string = string + data + data = sock.recv(1024) +sock.close() + +print string + +sys.exit(0) \ No newline at end of file