LWP Use Multiple IP Addresses On A Multihomed Machine
| |
| The Bush Survival Guide - 250 Ways to Make It Through The NExt Four Years Without Misunderestimating the Dangers Ahead, and Other Subliminable Stategeries |
|
Links:
| |
Subjects > Computers > Internet
Remember how I was wondering how to send pings, and web requests, and other net requests, from something other than the first IP address bound to a multihomed machine?
After years of wondering how to do this, I decided to spend a few hours single stepping through the perl libraries, since the main place I want to do this from is from the [spiders] that I write. I got rid of some of my internet servers recently, so I now have less places to run spiders from. Sometimes I need to run a lot of copies of a given spider so I can get thousands of requests finished faster.
After a couple of hours, I finally discovered a place in the perl runtime libraries where I could specify a localaddress which could be one of the addresses of the machine. So my click11 server, that has a dozen IP addresses bound to it, I can send a web get request from a perl program from any of the IP addresses on the machine.
Then I was trying to figure out how to hack this into the libraries, since at first I just hard coded an alternate address into the perl library. I finally figured out what a somewhat odd thing was that I’d been stepping over. Then finally how to set the value it was returning. Now that I know what to do, I did a search for that variable, EXTRA_SOCK_OPTS, and found what I had been looking for.
binding LWP to a specific interface After search and googleing for an answer a nice fellow in #perl (undernet) came up with the following: @LWP::Protocol::http::EXTRA_SOCK_OPTS = ( LocalAddr => q(ip.addr) ); Posted by sps at 10:54 AM
Too bad I never figured out that way to ask the question on google, or maybe I could have found the solution a lot sooner…..
So this doesn’t help me for stuff run from the command line like ping, or for the .NET framework spiders I write in C#, but maybe I can find something for them too. Turns out it looks like at the socket level, the magic thing is to bind to a specific address before the connect statement actually does the web request. It appears the default is to specify ANY_ADDR and let the winsock layer choose something.
Check out [Facts About Trees]
|
Interested in What To Do With Leftovers?