By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,570 Members | 1,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,570 IT Pros & Developers. It's quick & easy.

python socket proxy

P: n/a
Hi all

I am trying to create a lighweight tcp proxy server.

I got this code from ActivePython documentation.
What I am trying to accomplish, is I need to connect to local instance
of the proxyserver (127.0.0.1). This server must then connect to a
remote jabber server, send data, and listen to incoming data. When data
arrives, it must relay it back thru 127.0.0.1. The reason why I need I
am trying to get this to work, is I eventually want to make this server
connect over ssl/tls (which macromedia flash doesnt support natively).

The existing code only echoes back what it gets in, and note what it
gets back from the remote server. Help would be appreciated

Expand|Select|Wrap|Line Numbers
  1. # Echo server program
  2. import socket
  3.  
  4. HOST = '127.0.0.1'                 # Symbolic name meaning the local
  5. host
  6. PORT = 50007              # Arbitrary non-privileged port
  7. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  8. s.bind((HOST, PORT))
  9. s.listen(1)
  10. conn, addr = s.accept()
  11. print 'Connected by', addr
  12. while 1:
  13. data = conn.recv(1024)
  14. print (data)
  15. if not data: break
  16. conn.send(data)
  17. conn.close()
  18.  
  19.  
  20. # Echo client program
  21. import socket
  22.  
  23. HOST = 'remoteserver.com'    # The remote host
  24. PORT = 5222              # The same port as used by the server
  25. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  26. s.connect((HOST, PORT))
  27. s.send('Hello, world')
  28. data = s.recv(1024)
  29. print data
  30. s.close()
  31. print 'Received', repr(data)
  32.  
thanks

Jun 6 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
js*****@gmail.com wrote:
Hi all

I am trying to create a lighweight tcp proxy server.

[...]

There is a bunch of nice recipies in the Python Cookbook on port
forwarding. In the [1] and [2] case it should be fairly simple to add
an extra authentication step with pyOpenSSL.

[1] http://aspn.activestate.com/ASPN/Coo.../Recipe/483730
[2] http://aspn.activestate.com/ASPN/Coo.../Recipe/114642
[3] http://aspn.activestate.com/ASPN/Coo.../Recipe/483732

best,
fw

Jun 6 '06 #2

P: n/a
Hi

Thanks for the reply.

I found a proxy that works for me. Now I would like to know if its
possible to run a python script, so its not visible in the cmd window
(windows, i know, its bad :-) ) Maybe run it as a windows service?

Filip Wasilewski wrote:
js*****@gmail.com wrote:
Hi all

I am trying to create a lighweight tcp proxy server.

[...]

There is a bunch of nice recipies in the Python Cookbook on port
forwarding. In the [1] and [2] case it should be fairly simple to add
an extra authentication step with pyOpenSSL.

[1] http://aspn.activestate.com/ASPN/Coo.../Recipe/483730
[2] http://aspn.activestate.com/ASPN/Coo.../Recipe/114642
[3] http://aspn.activestate.com/ASPN/Coo.../Recipe/483732

best,
fw


Jun 7 '06 #3

P: n/a
Simplest way would be to rename your python file with a .pyw extension
instead of a .py extension.
If you're looking for windows services, checkout
win32serviceutil.ServiceFramework in pywin32.

Jeethu Rao

js*****@gmail.com wrote:
Hi

Thanks for the reply.

I found a proxy that works for me. Now I would like to know if its
possible to run a python script, so its not visible in the cmd window
(windows, i know, its bad :-) ) Maybe run it as a windows service?

Filip Wasilewski wrote:
js*****@gmail.com wrote:
Hi all

I am trying to create a lighweight tcp proxy server.

[...]

There is a bunch of nice recipies in the Python Cookbook on port
forwarding. In the [1] and [2] case it should be fairly simple to add
an extra authentication step with pyOpenSSL.

[1] http://aspn.activestate.com/ASPN/Coo.../Recipe/483730
[2] http://aspn.activestate.com/ASPN/Coo.../Recipe/114642
[3] http://aspn.activestate.com/ASPN/Coo.../Recipe/483732

best,
fw



Jun 7 '06 #4

P: n/a
cool, nice one, thanks.
Jeethu Rao wrote:
Simplest way would be to rename your python file with a .pyw extension
instead of a .py extension.
If you're looking for windows services, checkout
win32serviceutil.ServiceFramework in pywin32.

Jeethu Rao

js*****@gmail.com wrote:
Hi

Thanks for the reply.

I found a proxy that works for me. Now I would like to know if its
possible to run a python script, so its not visible in the cmd window
(windows, i know, its bad :-) ) Maybe run it as a windows service?

Filip Wasilewski wrote:
js*****@gmail.com wrote:

Hi all

I am trying to create a lighweight tcp proxy server.

[...]

There is a bunch of nice recipies in the Python Cookbook on port
forwarding. In the [1] and [2] case it should be fairly simple to add
an extra authentication step with pyOpenSSL.

[1] http://aspn.activestate.com/ASPN/Coo.../Recipe/483730
[2] http://aspn.activestate.com/ASPN/Coo.../Recipe/114642
[3] http://aspn.activestate.com/ASPN/Coo.../Recipe/483732

best,
fw



Jun 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.