Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Different Outbound IPs in Perl

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!

like image 257
Russell C. Avatar asked Aug 07 '10 21:08

Russell C.


1 Answers

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/");
like image 174
Jonas Avatar answered Oct 24 '22 07:10

Jonas