in reply to Get the IP Address

For HTTP requests, there's a Client-Peer header that you can access in the response...

use LWP::UserAgent; use HTTP::Request::Common; my $url = 'http://www.perlmonks.org/'; my $browser = LWP::UserAgent->new; my $response = $browser->request( GET $url ); if ( $response->is_success ) { my($ip,$port) = split /:/, $response->header("Client-Peer"); print "Connected to $ip on port $port\n"; } else { print "Couldn't get $url: ", $response->status_line, "\n"; }

... although it dissappeared briefly before (and then re-appeared with) LWP 5.66, so you may need to upgrade, downgrade or hack LWP::Protocol::http if you find it's absent from the version you have installed.

    --k.


Replies are listed 'Best First'.
Re: Re: Get the IP Address
by Anonymous Monk on Aug 26, 2003 at 23:28 UTC
    Thanks for the reply! This is close but I need to have this work for unsuccessful connections as well. Any ideas on how to get the info if we fail to make a connection?
      Then I am not sure that LWP on its own is going to be the answer. You might have to query the DNS, record the IP and make the request using the IP.

      Thats how I have done it in the past.

      jdtoronto