473,659 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Controlling source IP address within urllib2

Dan
Does anybody know how to control the source IP address (IPv4) when
using the urllib2 library? I have a Linux box with several IP
addresses in the same subnet, and I want to simulate several
individuals within that subnet accessing web pages independently. I
need the functionality of urllib2 because there will be redirects and
other HTTP-type functions to implement. It would be nice if I could
create (and bind) sockets myself and then tell the urllib functions to
use those sockets. Perhaps there is some sort of "back-door" way of
doing this??? Any hints are appreciated!
-Dan

Jul 19 '05 #1
4 3733
Dan
John,
Thanks for your input. I can kind of see the light in this, but I'm
having difficulty knowing where the "do_open" method comes from. Also,
I'll need to follow redirects, so I assume then I would add a
HTTPRedirectHan dler instance to the urllib2.build_o pener. (?) Thanks
again for your help.
-Dan

Jul 19 '05 #2
"Dan" <to****@hotmail .com> writes:
John,
Thanks for your input. I can kind of see the light in this, but I'm
having difficulty knowing where the "do_open" method comes from. Also,
AbstractHTTPHan dler

I'll need to follow redirects, so I assume then I would add a
HTTPRedirectHan dler instance to the urllib2.build_o pener. (?) Thanks


No. It does that by default.
John
Jul 19 '05 #3
Dan
John,
Thanks again for your help!
I think that the do_open function in AbstractHTTPHan dler does not
return the correct object type as required by the opener. When I
include the code you recommended, the implementation comes back with
the message, "urlopen error unknown url type: http". Strange, because
I would think that overriding the "http_open" function in the handler
would have signaled that this function is capable of handling http. If
I call the HTTPHandler base class "http_open" function from within the
derived class, all works okay, but of course, I don't get to use the
source IP address I wanted to use.
I'll keep trying and let you know what I find.
-Dan

Jul 19 '05 #4
Dan
Just FYI ... I finally got this to work. Unfortunately, I was unable
to use the urllib2 library. The embedded Linux team here informed me
that the urllib2 library will not be available on the machine I wanted
to deploy on, so I had to go back to using the urllib and httplib
libraries. After trying several things, I finally gave up and hacked
the library code directly. It turned out to be quite easy. I just had
to wedge in a "self.sock.bind ()" call in front of the
"self.sock.conn ect()" call within the HTTPConnection class inside the
httplib library. (I used the bind() function to nail down the source
IP address of the client.) Of course, I had to weave in some code that
allowed me to pass the client IP address through the URLopener class in
the urllib library. Everything seems to work so far.

John, thanks again for your help. You pointed me in the right
direction.

-Dan

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6094
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line #80 and line # 38 are the first line offenders. --> --> -->
5
7395
by: Pascal | last post by:
Hello, I want to acces my OWA (Outlook Web Acces - http Exchange interface) server with urllib2 but, when I try, I've always a 401 http error. Can someone help me (and us)? Thanks. here's my pyscript:
3
1463
by: rock69 | last post by:
Hi all :) I got this address: http://www.infomedia.it/immagini/riviste/covers/cp/cp137.jpg and I would like to download that image and save it to a local file. How do you do that in Python?
1
3366
by: Ray Slakinski | last post by:
Hello, I have defined a function to set an opener for urllib2, this opener defines any proxy and http authentication that is required. If the proxy has authencation itself and requests an authenticated file I get a HTTP status code of 401 (Unauthorized access of the file being requested) I do see in the headers the Proxy-authorization and the Authorization headers being sent for the request.
1
2384
by: joemynz | last post by:
Help please with a URLError. Invoking a url that works in Firefox and IE results in a "urlerror 7, no address ..." in python. I need to debug why. Traceback is below. There's a redirect when the url is invoked (it's part of a chain) - you can see it using liveheaders in firefox. What is the best way to debug this? I tried setting debug on HTTPConnection but this doesn't work (from some web posts, setting debug is broken in 2.4). What's...
1
5752
by: Alessandro Fachin | last post by:
I write this simply code that should give me the access to private page with htaccess using a proxy, i don't known because it's wrong... import urllib,urllib2 #input url url="http://localhost/private/file" #proxy set up
5
3748
by: cjl | last post by:
Hi. I am trying to screen scrape some stock data from yahoo, so I am trying to use urllib2 to retrieve the html and beautiful soup for the parsing. Maybe (most likely) I am doing something wrong, but when I use urllib2.urlopen to fetch a page, and when I view 'page source' of the exact same URL in firefox, I am seeing slight differences in the raw html.
5
1717
by: pyapplico | last post by:
Is there any possible way that I can place a .py file on the internet, and use that source code in an .py file on my computer?
5
2056
by: Timothy Grant | last post by:
On Tue, Aug 5, 2008 at 2:50 PM, David York <davideyork@gmail.comwrote: I'm not sure what you are trying to accomplish. The machine I'm typing this on has a 192.168.x.x number. The router that gave it to me also has a 192.168.x.x number. However, I know that that is not the IP that the world sees when my packets finally leave the building. What if your machine has multiple interface cards in it? What are you trying to accomplish?
0
8339
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
8751
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...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
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
5650
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
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
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
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.