Whamcloud - gitweb
LU-14786 lod: create missing debugfs file
[fs/lustre-release.git] / lustre / tests / resolveip
1 #!/usr/bin/perl
2 =pod
3
4 =head1 NAME
5
6 resolveip - Resolve IP address for given hostname
7
8 =head1 DESCRIPTION
9
10 Tries to resolve IP address of given hostname and return its value,
11 returns empty value if unable to detect it.
12
13 =cut
14
15 use Socket;
16 $hostname = $ARGV[0];
17
18 sub resolve_ip {
19         ($hostname) = @_;
20
21         return unless defined $hostname;
22
23         $packed_ip = gethostbyname($hostname);
24         if (defined $packed_ip) {
25                 $ip_address = inet_ntoa($packed_ip);
26                 return $ip_address;
27         }
28 }
29
30 $ip = resolve_ip($hostname);
31
32 if (not $ip or $ip eq '') {
33         print STDERR "Unable to detect ip address for host: '$hostname'\n";
34         exit 1;
35 }
36
37 print $ip;
38
39 exit 0;