Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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, HTTP.pm. 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!
jjdeterick

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 'http://www.perl.com/%Euser/gisle.gif'; # 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.
    --

    Zigster
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 http://www.example.com/ or http://www.example.com:8080/url.html.

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-29 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found