Computing.Net > Forums > Programming > Perl: local IP info w/o knowing

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Perl: local IP info w/o knowing

Reply to Message Icon

Name: R Wideman
Date: October 16, 2002 at 20:17:55 Pacific
OS: win2k
CPU/Ram: doesnt matter
Comment:

I am wanting to get my IP and Hostname via PERL w/o knowing either the ip or the hostname. Is there a way to do this? It seems that this is the closest to what i want but its requiring know info and also it doesnt print out anything:

#!perl
use Socket;
$ip=gethostbyname 'hostname';
print "My IP Address is: $ip";



Sponsored Link
Ads by Google

Response Number 1
Name: JSLover
Date: October 19, 2002 at 22:12:29 Pacific
Reply:

The ip of the computer you're running the script on right? Not have a server tell you your ip? To get the ip/hostname of the server running the script...use...

#!/usr/bin/perl
$ip="$ENV{'SERVER_ADDR'}";
$hostname="$ENV{'SERVER_NAME'}";
print "My IP Address is: $ip\n";
print "My Hostname is: $hostname";

...or more directly...

#!/usr/bin/perl
print "My IP Address is: $ENV{'SERVER_ADDR'}\n";
print "My Hostname is: $ENV{'SERVER_NAME'}\n";

I just noticed you said your OS is Win2K...you don't need the 1st line in the file...
#!/usr/bin/perl
...I'm not sure if it'll mess anything up by being there on Win2K but if it don't give an error leave it unless you'll never use it on a unix then delete.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Perl: local IP info w/o knowing

Perl extracting mib info w/net-snmp www.computing.net/answers/programming/perl-extracting-mib-info-wnetsnmp/9292.html

Send email w/o extra line breaks www.computing.net/answers/programming/send-email-wo-extra-line-breaks/14779.html

C++ IP address combination task www.computing.net/answers/programming/c-ip-address-combination-task/11864.html