Hi,
I am building a hash from an open filehandle. Example data shown below...
Hostname : myhost
Network Card e1000g0 : 0:0:0:0:0:0
Speed :
IP Address : 172..1.1.1 : myhostI3
Netmask : 255.255.254.0
Network Card e1000g0:1 :
Speed : ## Virtual IP ##
IP Address : 172.1.1.3 : myhost myhost.com
Netmask : 255.255.255.0
Network Card e1000g0:2 :
Speed : ## Virtual IP ##
IP Address : 172.1.1.2 : myhostI2
Netmask : 255.255.254.0
Network Card e1000g2 : 0:0:0:0:0:0
Speed :
IP Address : 172.1.1.4 : myhostibkup
Netmask : 255.255.254.0
I have extracted the hostname to the hash ...
if ($_ =~ /^(\s)*Hostname(\s)*:/) {
chop;
($pants, $details{"Hostname"}) = (split /: /);
}
I am only interested in the primary network interface and I can get the IP address line for the primary hostname ...
if ($_ =~ /^(\s*IP Address\s+:)(.*:)(.*$detai
ls{"Hostna
me"}\s+)/)
{($pants, $details{"IPAddress"}) = (split /: /)}
But I am not sure how to extract the Netmask detail following on the next line to $details{"Netmask"} ensuring that I get the Netmask belonging to the primary interface and ignoring the others.
Hope this makes sense.
Start Free Trial