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

I've been looking for a way to get the Hostname and IP address with perl, from the computer that is running the script. I want it in a text form so that I can identify the computer on the server side. I'm not sure how to do this, and searching about I've found some things that look like they would do that but I couldn't understand them to the point to use them. Any help would be great. Thanks, Michael

Replies are listed 'Best First'.
Re: Retrieving network information
by Corion (Patriarch) on Apr 03, 2006 at 20:23 UTC

    Have you looked at Sys::Hostname? Or maybe you wanted gethostbyaddr? I'm not exactly sure which of the two you want, because you talk of a "Computer that is running the script", and you also talk of "on the server side" - a Perl script is run on one computer.

    If you're thinking of a script that runs on a webserver, and which is triggered by a client connecting, then you want gethostbyaddr, together with (I believe) $ENV{CLIENT_IP}.

    If you're thinking of a script that many clients in your network run, then Sys::Hostname is what you want.

      Yeah, I meant the client side script, sorry about any confusion. Sys::Hostname seems to be just what I want. I saw gethostbyaddr before which is where I got mixed up, I see why now I was trying to get the local hostname with the thing designed to get the remote one. Thank you very much for you help.