Hi. This is the qmail-send program at tmtowtdi.perl.org. I'm afraid I wasn't able to deliver your message to the following addresses. This is a permanent error; I've given up. Sorry it didn't work out. <[EMAIL PROTECTED]>: This mailinglist does not accept postings crossposted to newsgroups - Contact [EMAIL PROTECTED] for help --- Below this line is a copy of the message. Return-Path: <[EMAIL PROTECTED]> Received: (qmail 10528 invoked from network); 31 Mar 2000 10:23:55 -0000 Received: from mail49-s.fg.online.no (HELO mail49.fg.online.no) (148.122.161.49) by tmtowtdi.perl.org with SMTP; 31 Mar 2000 10:23:55 -0000 Received: from eik (ti21a62-0097.dialup.online.no [130.67.197.225]) by mail49.fg.online.no (8.9.3/8.9.3) with ESMTP id MAA14176 for <[EMAIL PROTECTED]>; Fri, 31 Mar 2000 12:23:52 +0200 (MET DST) Received: (qmail 7340 invoked by uid 500); 31 Mar 2000 10:22:31 -0000 Sender: [EMAIL PROTECTED] Newsgroups: comp.lang.perl.misc Cc: [EMAIL PROTECTED] Subject: Re: HTTP Request References: <EEQE4.609$[EMAIL PROTECTED]> From: Gisle Aas <[EMAIL PROTECTED]> Date: 31 Mar 2000 11:53:30 +0200 Message-ID: <[EMAIL PROTECTED]> Organization: Aas Software User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.3 In-Reply-To: "Dan Manion"'s message of "Thu, 30 Mar 2000 15:29:50 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Posted-To: comp.lang.perl.misc Lines: 72 The following message is a courtesy copy of an article that has been posted to comp.lang.perl.misc as well. "Dan Manion" <[EMAIL PROTECTED]> writes: > Ok let me fist start off with the problem I am trying to solve. I need to > make a web request where I can specify the IP that the request is being > sending with. I am not trying to spoof. Lets say I have the IP's > 10.10.10.1-100 bound to one virtual hosting machine who's IP is 10.10.10.1 . > If I run the code below I the request comes from host computers IP. I would > like to be able to specify the IP that I am sending with. So if I have > 10.10.10.50 bound to mybutt.com .. I can make a request as if the request > was being sent from mybutt.com and not my default IP (10.10.10.1). > > So I guess I'm wondering if this is even possible using a standard library > and if so what libraries will I have to sub class to get it to work. Any > advice / input / suggestions are appreciated! This has been requested enough times that I think I just have to make it easier :-) What you can do for now is to replace the class that handles lower level http communication by calling LWP::Protocol::implementor(). The new class would then have to set up a socket where it specify LocalAddr as well. The rest of its implementation it could just inherit from the standard http protocol module. This should be an demo: #!/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 LWP::Protocol; LWP::Protocol::implementor("http", "MyHTTP"); my $ua = LWP::UserAgent->new; my $request = HTTP::Request->new(GET => 'http://www.microshaft.com/'); my $response = $ua->request($request); print $response->as_string; __END__ Regards, Gisle
