5

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!

4

1 に答える 1

9

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/");
于 2010-08-07T22:37:19.283 に答える