- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find IP address of host
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 11:49 AM
07-06-2005 11:49 AM
find IP address of host
I need to write a PERL script which returns the IP address of the host.
Can anyone please help.
Thanks,
Pat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 03:22 PM
07-06-2005 03:22 PM
Re: find IP address of host
assuming you are on a machine with fully qualified domain name,
this will work
#!/usr/bin/perl -wT
use IO::Socket;
$hostname="hostname.yourdomain.com"; #change this to your hostname
my($addr)=inet_ntoa((gethostbyname($hostname))[4]);
print "$addr\n";
there could be other variations that will give you servers behind the routers etc.
thanks
DP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 04:48 PM
07-06-2005 04:48 PM
Re: find IP address of host
# perldoc -q hostname
use Sys::Hostname;
my $host = hostname();
my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost'));
print "Hostname = $host" . "\tIP-Address = $addr" . "\n";
You can easily get from shell as,
# getip
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 08:21 PM
07-06-2005 08:21 PM
Re: find IP address of host
If you want to avoid the import of Socket (just to get inet_ntoa() and the likes)
it requires just two statements, like
chomp($this_node=qx(/usr/bin/uname -n));
$this_ip = join '.', unpack('C4',((gethostbyname $this_node)[-1])[0]);
If you're unhappy with external calls (e.g. taint mode) you could as well get the node name from the POSIX module (at the cost of import)
e.g.
use POSIX 'uname';
($this_node) = (uname)[1];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2005 05:06 PM
07-07-2005 05:06 PM
Re: find IP address of host
Please check this URL:
http://www.perl.com/pub/a/2002/11/20/dns.html
http://home.xnet.com/~efflandt/ip2host.html
The above URL will give good idea about IP 2 host conversion.
Regards
Ganesha Sridhara