473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

python socket proxy

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
4 12445
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fuzzyman | last post by:
In a nutshell - the question I'm asking is, how do I make a socket conenction go via a proxy server ? All our internet traffic has to go through a proxy-server at location 'dav-serv:8080' and I...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
0
by: starmaven | last post by:
I'm looking for a way to implement socket connections through a SOCKS (4/5) proxy in Python. I don't want to use Twisted or anything complicated - just a simple replacement for the socket library....
1
by: Rolln_Thndr | last post by:
I'm vey new to network programing and have a few rather fundemental questions. I'm creating a very basic UDP proxy server and having a few issues regarding the sockets. Is it possible to change...
7
by: | last post by:
Hi all, I have a simple .aspx page running on net 2.0 that is trying to do a http post to a remote server. Here is the code Private Function ProcessRequests(ByVal strbody As String) As String...
1
by: Ron Davis | last post by:
I have recently discovered Python and like it quite a bit. I would like to use it on a new project I am starting. The project will gather data from several web services and present the collected...
0
by: Dan Lenski | last post by:
Hi all, I've recently written an HTTP proxy server for the Motorola E815 cell phone, based on Suzuki Hisao's "Tiny HTTP Proxy" (http:// www.okisoft.co.jp/esc/python/proxy/). This cell phone...
0
by: Astan Chee | last post by:
Hi, I have a proxy server that requires authentication on a non-standard port and Im trying to connect to it via socket.connect() I tried doing this: import socket server =...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.