Ok here is a simpler solution (maybe not terribly elegant, but it works) - only for http, I hope SSL will be the same:
use strict; use LWP::UserAgent; my $localPort; sub setLocalPort {$localPort = shift;} package myHttp; use vars qw(@ISA); require LWP::Protocol::http; @ISA = qw( LWP::Protocol::http ); sub socket_class {return "LWP::Protocol::http::Socket";} sub _new_socket { my($self, $host, $port, $timeout) = @_; my $s = $self->SUPER::_new_socket($host,$port,$timeout); main::setLocalPort($s->sockport()); print "Local port: ",$s->sockport(),"\n"; return $s; } package main; LWP::Protocol::implementor( http => 'myHttp' ); my $ua = LWP::UserAgent->new(ssl_opts => { SSL_verify_mode => 'SSL_VER +IFY_NONE'},); $ua->agent('Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Triden +t/5.0)'); $ua->max_size(50000000); # 50MB at most $ua->timeout(45); my $request = HTTP::Request->new(GET => "http://www.google.ch/"); $request->protocol('HTTP/1.0'); # we don't want chunked replies $request->header('Accept' => '*/*'); $request->header('Accept-Encoding' => ''); # we don't want packed re +sults $request->header('Connection' => 'Close'); $request->header('Cache-Control' => 'no-cache'); my $resp = $ua->request($request); if ($resp->is_success) { my $data = $resp->content; print "$data\n"; print "Local port: $localPort\n"; }

In reply to Re^5: LWP: How to find out local port number? (ISA) by klaymen
in thread LWP: How to find out local port number? by klaymen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.