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, ho开发者_如何转开发wever 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!
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/");
精彩评论