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:rotocol::http';
sub _new_socket # mostly copied from LWP:rotocol::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:umper;
use LWP:rotocol;
LWP:rotocol::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__
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:rotocol::http';
sub _new_socket # mostly copied from LWP:rotocol::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:umper;
use LWP:rotocol;
LWP:rotocol::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__