http://qs1969.pair.com?node_id=59161

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

Hi.

I'm using HTTP::Daemon on Windows 95.

If I use the following: $d->url

HTTP::Daemon will show me the host name of the server with the port number. Example: http://computer:1285/

Isn't there a command, that instead of getting the host name, it will get the IP address of the server?

Ralph :)

Replies are listed 'Best First'.
Re: Getting IP with HTTP::Daemon
by MeowChow (Vicar) on Feb 18, 2001 at 02:11 UTC
    This is a FAQ. Look here.
Re: Getting IP with HTTP::Daemon
by IndyZ (Friar) on Feb 18, 2001 at 01:47 UTC
    First, write or regex to get the hostname, by itself, out of $d->url. I will leave this as a skill building excercise for you. Then, try this:
    use Socket; @addresses = gethostbyname($name) or die "Can't resolve $name: $!\n"; @addresses = map { inet_ntoa($_) } @addresses[4 .. $#addresses];
    @addresses will contain a list of IP addresses. I think that this code is verbatim from the Perl Cookbook, I just copied and pasted it out of an old project of mine.
Re: Getting IP with HTTP::Daemon
by Anonymous Monk on Feb 18, 2001 at 21:42 UTC
    Hi.

    I've tried using the first example and the one's in the FAQ, but they won't work. Many are only for linux, and I'm running it on windows 95.

    The one with the gethostbyname(hostname) just returns a bunch of unreadable symbols.

    Isn't there another way of getting the IP address of the computer?

    Ralph :)