spill has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use Class::Struct; my $HostID = "0"; struct Adapter => { ip => '$', mac => '$', }; struct Host => { hostid => '$', hostname => '$', interface => '@', }; while (<STDIN>) { s/\r|\n//g; if ( /Host Name.*?:\s*(.*)/ ) { $c = Host->new(); $c->hostid($HostID); $c->hostname($1); printf ("hostid = %s\n", $c->hostid); printf ("hostname = %s\n", $c->hostname); $HostID++; } if ( / adapter/ ) { while (<STDIN>) { s/\r|\n//g; if ( /Physical Address.*?:\s*(.*)/ ) { $a=Adapter->new(); $a->mac($1); push @{$c->interface}, $a; printf ("Adapter = %s\n", $c->interface(0)->mac); if ($c->interface(1)) { printf ("Adapter = %s\n", $c->interface(1)->mac); } if ($c->interface(2)) { printf ("Adapter = %s\n", $c->interface(2)->mac); } } if ( /Lease Expires.*?:\s*(.*)/ ) { last; } } }
IP Config Windows IP Configuration Host Name . . . . . . . . . . . . : axter-win2003 Primary Dns Suffix . . . . . . . : Axter2.home Node Type . . . . . . . . . . . . : Hybrid IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No DNS Suffix Search List. . . . . . : Axter2.home brnmll01.nj.comcast.net Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : brnmll01.nj.comcast.net Description . . . . . . . . . . . : SMC EtherPower II 10/100 Etherne +t Adapter Physical Address. . . . . . . . . : 00-E0-29-0A-F5-E2 DHCP Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.0.6 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.0.1 DHCP Server . . . . . . . . . . . : 192.168.0.1 DNS Servers . . . . . . . . . . . : 127.0.0.1 192.168.0.1 Lease Obtained. . . . . . . . . . : Tuesday, September 16, 2003 6:18 +:13 PM Lease Expires . . . . . . . . . . : Friday, September 19, 2003 6:18: +13 PM ipconfig completed IP Config Windows 98 IP Configuration Host Name . . . . . . . . . : LAPTOP.no.cox.net DNS Servers . . . . . . . . : 205.152.132.235 181.171.2.200 10.10.10.1 Node Type . . . . . . . . . : Broadcast NetBIOS Scope ID. . . . . . : IP Routing Enabled. . . . . : No WINS Proxy Enabled. . . . . : No NetBIOS Resolution Uses DNS : No 0 Ethernet adapter : Description . . . . . . . . : PPP Adapter. Physical Address. . . . . . : 44-45-53-54-00-00 DHCP Enabled. . . . . . . . : Yes IP Address. . . . . . . . . : 181.171.2.147 Subnet Mask . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . : 181.171.2.147 DHCP Server . . . . . . . . : 255.255.255.255 Primary WINS Server . . . . : Secondary WINS Server . . . : Lease Obtained. . . . . . . : 01 01 80 12:00:00 AM Lease Expires . . . . . . . : 01 01 80 12:00:00 AM 1 Ethernet adapter : Description . . . . . . . . : PPP Adapter. Physical Address. . . . . . : 44-45-53-54-00-01 DHCP Enabled. . . . . . . . : Yes IP Address. . . . . . . . . : 0.0.0.0 Subnet Mask . . . . . . . . : 0.0.0.0 Default Gateway . . . . . . : DHCP Server . . . . . . . . : 255.255.255.255 Primary WINS Server . . . . : Secondary WINS Server . . . : Lease Obtained. . . . . . . : Lease Expires . . . . . . . : 2 Ethernet adapter : Description . . . . . . . . : D-Link AIRPLUS Wireless LAN Adapter Physical Address. . . . . . : 00-80-C8-B5-76-1F DHCP Enabled. . . . . . . . : Yes IP Address. . . . . . . . . : 10.10.10.104 Subnet Mask . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . : 10.10.10.1 DHCP Server . . . . . . . . : 10.10.10.1 Primary WINS Server . . . . : Secondary WINS Server . . . : Lease Obtained. . . . . . . : 06 19 03 2:51:53 PM Lease Expires . . . . . . . : 06 26 03 2:51:53 PM ipconfig completed
janitored by ybiC: Balanced <readmore> tags around code and sample input
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Having problems with class::struct
by tedrek (Pilgrim) on Dec 11, 2003 at 20:49 UTC | |
by spill (Novice) on Dec 11, 2003 at 21:12 UTC | |
by tedrek (Pilgrim) on Dec 11, 2003 at 21:50 UTC | |
|
Re: Having problems with class::struct
by jmanning2k (Pilgrim) on Dec 11, 2003 at 22:01 UTC | |
by dragonchild (Archbishop) on Dec 12, 2003 at 13:29 UTC |