473,671 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12466
js*****@gmail.c om 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.c om 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
win32serviceuti l.ServiceFramew ork in pywin32.

Jeethu Rao

js*****@gmail.c om 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.c om 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
win32serviceuti l.ServiceFramew ork in pywin32.

Jeethu Rao

js*****@gmail.c om 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.c om 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
17697
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 need to make a socket connection through it. The reason (with code example) is as follows : I am hacking "Tiny HTTP Proxy" by SUZUKI Hisao to make an http proxy that modifies URLs. I haven't got very far - having started from zero knowledge of...
10
3681
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. Andrew dalke@dalkescientific.com
0
5900
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. The only thing I could find was for Python 1.0.1, and I couldn't get that to compile. Apparently it's really trivial to rewrite the socket library (a manner of a few lines) but I am not a protocol or networking guru. Can anyone help me?
1
3075
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 the properties of a socket WITHOUT closing it and creating a new one? Basically, I need to change the port of a bound socket, but the only way I have found to do this so far is to close the exisitng socket and create a new one. This in itself...
7
2926
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 Dim returnstr As String Dim URL As String = "http://www.dydomain.com/test.asp"
1
2063
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 data to browser users through a web server. So basically I need a full-time web server and a separate way to poll web services for their data. There is no database involved. The problem is that I have tried several Python web servers...
0
1920
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 allows free Internet access if you change the default proxy server, but it has a severely buggy HTTP client implementation which will freeze if there's no Content-Length header. Basically, it's impossible to read normal web pages without some...
0
1053
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 = ("username:password@proxyaddrs.com",1234) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(server) I keep getting the
0
8476
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5695
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2810
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.