Skip to content

Instantly share code, notes, and snippets.

@ceekz
Created July 12, 2012 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceekz/3099041 to your computer and use it in GitHub Desktop.
Save ceekz/3099041 to your computer and use it in GitHub Desktop.
An IP address is used at random.
# サーバに割り当てた任意の IP アドレスを利用する
# (本コードではランダムに選択)
use LWP::UserAgent (@LWP::Protocol::http::EXTRA_SOCK_OPTS);
# ランダムに IP を選択
{
my @IP = qw(
203.0.113.1
203.0.113.2
203.0.113.3
203.0.113.4
203.0.113.5
);
push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, LocalAddr => $IP[rand(@IP)]);
}
my $ua = LWP::UserAgent->new(agent => 'Bot/0.1', keep_alive => 1);
my $html = $ua->get('http://www.example.com/')->content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment