Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Determining foreign port number

by jjdeterick (Curate)
on Mar 05, 2001 at 22:46 UTC ( #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

Comment on Determining foreign port number
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.

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 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

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-07-26 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls