Socket problem

Hasan Diwan diwanh at rcs-sgi.server.rpi.edu
Fri Jun 8 10:28:01 EDT 2001


I'm having problems with the socket.connect method... Code below, the
reason I'm using python 1.xx is that the target machine doesn't have
2.xx yet. The offensive line is denoted as such:

#!/usr/bin/env python
# proxy.py, sets up a generic TCP proxy... needs python 1.xx
"""
    Generic TCP proxy server using CGI
    expects: host, port
    returns: cli_port
"""
import cgi
field=cgi.FieldStorage()
form_ok=0
if (field["host"].value != "" or field["port"].value != ""):
    form_ok=1;
if not form_ok:
    print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
    print '<html><head><title>Error</title></head><body bgcolor="#000000"><center>The script makes no assumptions about hostname and port, so you must be verbose about it</center><hr><address><a href="mailto:hdiwan at hushmail.com">comments here, please</a></body></html>'
# Now start socket code
from socket import *
import errno
push=socket(AF_INET, SOCK_STREAM)
pull=socket(AF_INET, SOCK_STREAM)
push.bind(('',0)) #localhost, random port
pull.connect(field["host"].value, field["port"].value) # this line offends the python interpreter
push.listen(SOMAXCONN)
(localhost, cli_port) = push.getsockname()
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
print '<html><head><title>Success</title></head><body bgcolor="#000000"><center>Proxy successfully set up on port <font color="#ff0000">',cli_port,'</font> to <font color="#00ff00">',host,':',port,'</font>Have a good time</center></body></html>'



More information about the Python-list mailing list