Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Determining foreign port number

by jjdeterick (Curate)
on Mar 05, 2001 at 22:46 UTC ( [id://62312]=perlquestion: print w/replies, xml ) Need Help??

jjdeterick has asked for the wisdom of the Perl Monks concerning the following question:

I'm working with some perl code that basiclly traverses and indexes a given list of URLs. This code uses, among other modules, I have a need to check and log the port number used by these foreign hosts. Basiclly I need to make a note of those not using PORT 80. Does anyone know of any easy way to do this? If not, does anyone know of any way to do this?
Thanks in advance!

Replies are listed 'Best First'.
Re: Determining foreign port number
by zigster (Hermit) on Mar 05, 2001 at 23:12 UTC
    I hope I understand your question correctly, if I have missed the point msg me or follow up and I will try and help some more.

    Its coded in the url http://<Host:Port>/Resource .. parse the url with a regexp or use URI::URL Which is part of libwww-perl I have not used URI::URL before but a quick search finds that it has been mentioned on pm lots of times .. checkout super search search for URI::URL.

    You are looking for something like (ripped from the pod)

    use URI::URL; $url = new URI::URL ''; # Retrieving Network location (netloc) components: $user = $url->user; $password = $url->password; $host = $url->host; $port = $url->port; # returns default if not defined
    There are lots of other permutations so take a look at the links above.

Re: Determining foreign port number
by tomhukins (Curate) on Mar 05, 2001 at 23:11 UTC
    use URI::URL (); my $url = URI::URL->new($url_as_string) or warn "URL error"; print $url->port

    $url_as_string would be the full URL you are parsing, such as or

Re: Determining foreign port number
by archon (Monk) on Mar 05, 2001 at 22:59 UTC
    You can probably determine this from one of the environment variables stored in %ENV. For example, apache stores it in $ENV{'SERVER_PORT'}

    Use this script to print the environment of a CGI request:

    use strict; use CGI qw(:standard); print header, start_html; for my $k (sort keys %ENV) { print "$k = $ENV{$k}<br>"; } print end_html;

    HTH, HAND.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://62312]
Approved by root
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2024-04-18 16:24 GMT
Find Nodes?
    Voting Booth?

    No recent polls found