views:

79

answers:

1

We have a few different websites running on the same server that all access 1 particular web service with each having their own unique API key. Unfortunately the web service has a daily limit based on IP address (not API key) so while each of our sites is way under their daily limit, combined they are over the IP limit. When accessed via a web browser each website runs on a different static IP address, however when perl scripts are run under each of the website user account's their outbound IP address is identical.

My question is how can I make it so that each perl script uses the correct IP address of the particular site so that each one can stay within the daily limit of the web service? More simply, how can a perl script change the outbound IP address of the calls it's is making using the LWP perl module? Explanations are great but code examples would be even better.

Thanks in advance for your help!

+6  A: 

Using LWP::UserAgent you can simply use the ''local_address'' method to decide which IP address you want for outgoing connections:

my $ua = new LWP::UserAgent;
$ua->local_address("10.10.10.10");
my $response = $ua->get("http://stackoverflow.com/");
Jonas
You can also pass `local_address` as a parameter to the UA constructor. (Note: you should use `LWP::UserAgent->new` instead of `new LWP::UserAgent`. Indirect object syntax is best avoided.)
cjm
Worked like a charm. Thanks guys!
Russell C.