I need to write a little piece of code to simulate traffic from different source IP addresses and I'm wondering if that can be done by spoofing the addresses with Perl?
I tried Net::RAWIP and that worked, but I need to send some more complex HTTP traffic (namely POST data) and was unable to do so with RAWIP
With LWP I tried using ua->local_address but I get this response:
Can't connect to 10.x.x.x:8080
LWP::Protocol::http::Socket: Cannot assign requested address at /usr/lib/perl5/site_perl/5.10.0/LWP/Protocol/http.pm line 51.
This is the code I'm using:
#!/usr/bin/perl -w
use strict ;
use warnings ;
use LWP::UserAgent ;
use URI::URL ;
my $path = 'http://142.133.114.130:8080' ;
my $url = new URI::URL $path;
my $ua = LWP::UserAgent->new();
$ua->local_address('10.121.132.112');
$ua->env_proxy ;
my $effing = 'blaj.jpg' ;
my $response = $ua->post( $url,
'Content-Type' => "multipart/form-data",
'Content' => [ userfile => ["$effing" ]],
'Connection' => 'keep-alive' ) ;
print $response->decoded_content();