eth0 Link encap:Ethernet HWaddr 00:0C:29:0F:9B:82
inet addr:192.168.8.76 Bcast:192.168.8.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0f:9b82/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:280252 errors:0 dropped:0 overruns:0 frame:0
TX packets:106184 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:35501675 (33.8 MiB) TX bytes:11696548 (11.1 MiB)
Base address:0x1080 Memory:f4820000-f4840000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4664 errors:0 dropped:0 overruns:0 frame:0
TX packets:4664 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7952486 (7.5 MiB) TX bytes:7952486 (7.5 MiB)
####
open FILE,"config.txt" or die "cannot open file : $!";
$i = 1;
while() {
chomp ($_);
# print "===$_"."\n";
@arr=split /\s+/, $_;
#print "line is =>$arr[]". "\n\n";
print "Line $i ->$arr[0] $arr[1]"."\n";
foreach $line (@arr) {
#print "My Elements -> $line\n";
if ($line =~ (/^addr:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/)){
$ipaddr ="$1.$2.$3.$4\n";
print "$ipaddr";
}
}
$i++;
# print $_;
}
####
Line 1 ->eth0 Link
Line 2 -> inet
192.168.8.76
Line 3 -> inet6
Line 4 -> UP
Line 5 -> RX
Line 6 -> TX
Line 7 -> collisions:0
Line 8 -> RX
Line 9 -> Base
Line 10 ->
Line 11 ->lo Link
Line 12 -> inet
127.0.0.1
Line 13 -> inet6
Line 14 -> UP
Line 15 -> RX
Line 16 -> TX
Line 17 -> collisions:0
Line 18 -> RX
####
eth0 => 192.168.8.76
lo => 127.0.0.1