[NBLUG/talk] perl http request over alias nic

Walter Hansen gandalf at sonic.net
Wed May 24 17:52:27 PDT 2006


> On Wed, May 24, 2006 at 12:02:57PM -0700, Walter Hansen wrote:
>> Well I had thought of that, but I wanted to change the nic on the fly
>> rather than in a perament manner. I dug through a lot of modules, but
>> they
>> don't seem to alow interface selection.
>
> Just call bind() after socket() and before connect().  :)
>
> A hoary old text:  http://www.sonic.net/scott/ip/ipc_tutorial.ps
>
>  -Scott
> p.s. you can also do it using the Linux "ip" command, but that's not as
> portable...


I found this example on that thread and tried modifiying it to bind to an
IP address, but it doesn't appear to work for most html pages. I suspect
their rejecting it as using html 2.0.

#!/usr/bin/perl

    use IO::Socket;
    unless (@ARGV > 1) { die "usage: $0 host document ..." }
    $host = shift(@ARGV);
    $EOL = "\015\012";
    $BLANK = $EOL x 2;
    foreach $document ( @ARGV ) {
	$remote = IO::Socket::INET->new( Proto     => "tcp",
					 PeerAddr  => $host,
					 PeerPort  => "http(80)",
                                   LocalAddr => '64.142.127.130');

	unless ($remote) { die "cannot connect to http daemon on $host" }
	$remote->autoflush(1);
	print $remote "GET $document HTTP/1.0" . $BLANK;
	while ( <$remote> ) { print }
	close $remote;
    }


exit;





More information about the talk mailing list