added tcpconnect service. this code could be useful for htmlcontent too.
This commit is contained in:
parent
658c37206f
commit
6b54c149d1
2 changed files with 38 additions and 1 deletions
|
|
@ -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
|
||||
# maybe better: http://docs.python.org/2/library/urllib.html
|
||||
#
|
||||
# or look at tcpconnect.py! could be useful to.
|
||||
35
lib/service/tcpconnect.py
Normal file
35
lib/service/tcpconnect.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue