added tcpconnect service. this code could be useful for htmlcontent too.

This commit is contained in:
Johannes Findeisen 2013-05-30 04:53:10 +02:00
commit 2c80f1c1b8
2 changed files with 38 additions and 1 deletions

35
lib/service/tcpconnect.py Normal file
View file

@ -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)