Changing remote_addr on incoming request

T

tito

Hello:

I am trying to test an applications handling of different ip
(seriously)... THe application needs to identify the internal ip and
allow it to move to the next security check. I need to change the
incoming ip in order to validate this. Does anyone have any samples of
code that does this. I have been wrestling with one script I found but
when I set LocalAddr on the IO::Socket::Net object it gives me a null
socket.

Thanks,
T

Sample script:

#!/usr/bin/perl -w
use strict; #of course


package MyHTTP;
use base 'LWP::protocol::http';


sub _new_socket # mostly copied from LWP::protocol::http, added
LocalAddr
{
my($self, $host, $port, $timeout) = @_;


local($^W) = 0; # IO::Socket::INET can be noisy
my $sock = IO::Socket::INET->new(PeerAddr => '$host',
PeerPort => '$port',
LocalAddr => 'mybutt.com',
Proto => 'tcp',
Timeout => $timeout,
);
unless ($sock) {
# IO::Socket::INET leaves additional error messages in $@
$@ =~ s/^.*?: //;
die "Can't connect to $host:$port ($@)";
}
$sock;

}


package main;

use LWP::UserAgent;
use HTTP::Request;

use Data::Dumper;


use LWP::protocol;
LWP::protocol::implementor("http", "MyHTTP");


my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new(GET =>
'http://www.test.com/query.aspx?q=java');

print Dumper($request);
my $response = $ua->request($request);


print $response->as_string;


__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top