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!

xenoterracide
  • 16,274
  • 24
  • 118
  • 243
Russell C.
  • 1,649
  • 6
  • 33
  • 55
  • this question is about bypassing a site's security mechanism, and spoofing an IP address. From what I'm reading the site's don't have a seperate IP address. – xenoterracide Aug 07 '10 at 22:25
  • @Xeno: He specified "each website runs on a different static IP address". – Jim Lewis Aug 07 '10 at 22:29

1 Answers1

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/");
cjm
  • 61,471
  • 9
  • 126
  • 175
Jonas
  • 416
  • 2
  • 3
  • 3
    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 Aug 07 '10 at 23:42
  • What if there is no local address specified? How does LWP select an address if there are multiple addresses? Is it a random selection, round robin, etc? – MadHacker Oct 26 '16 at 13:35
  • Hi - this will only be for outgoing requests - but the response will still be connected to your real local IP address - or is that an incorrect assumption? This is not setting up a real proxy, it's just masking your outgoing IP address? – imbatman May 25 '17 at 08:29