Created
December 8, 2011 21:54
-
-
Save dlundquist/1448796 to your computer and use it in GitHub Desktop.
DNS round robin in perl LWP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use LWP; | |
use LWP::Protocol::http; # So we can manipulate EXTRA_SOCK_OPTS | |
use HTTP::Request::Common; | |
# LWP DNS round Robin | |
my $ua = LWP::UserAgent->new(); | |
my $req = HTTP::Request::Common::GET(shift @ARGV); | |
my ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($req->uri()->host()); | |
for my $addr (@addrs) { | |
my ($a,$b,$c,$d) = unpack('W4',$addr); | |
my $ip = "$a.$b.$c.$d"; | |
@LWP::Protocol::http::EXTRA_SOCK_OPTS = (PeerAddr => $ip); | |
my $res = $ua->request($req); | |
print $res->content() . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment