Solved

parse through a dhcp.netsh file

Posted on 2011-02-25
25
355 Views
Last Modified: 2012-05-11
Hi Guys,

I have a microsoft netsh dump. This file named. 1.2.3.4.netsh has invalid MAC addresses defined. meaning not enough digits. I have high lighted them.

Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.152 0002a56b94ce "stvfntest.bhmstv.help.corp" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.153 0a0a0a0a000a "aixtest1" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.154 0a0a0a0a000b "aixtest2" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.155 000c2903fdfd "LinuxIMG" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.156 a000000001 "VS_MGMT_336" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.157 a000000002 "VS_MGMT_352" "" ""


Is there a quick perl script that I can feed a file to report on stuff like this on a separate report log showing what DHCP server and Scope it came from?

Thank you kindly

0
Comment
Question by:richsark
  • 8
  • 8
  • 6
  • +2
25 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 34980191
There isn't any pre-made script that I'm aware of, but it would be very easy to write one that loops over the file splitting the line into fields and checks the length of the mac address field.

Have you tried writing it?  Do you have any code which you'd like someone to help you troubleshoot?
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 34980280

make_netsh_log.pl
------------------------
while (<>)
{
if (/Dhcp Server (\d+\.\d+\.\d+\.\d+) Scope (\d+\.\d+\.\d+\.\d+) Add reservedip (\d+\.\d+\.\d+\.\d+) ([a-f][0-9]*)/)
{
if (length($4)<12)
{
print "INVALID MAC $4\n";
}
}
}
0
 
LVL 1

Author Comment

by:richsark
ID: 34980329
Hello mankowitz:,

I ran the above perl,

But it showing:
$ perl make_netsh_log.pl merged.netsh

INVALID MAC a
INVALID MAC d0
INVALID MAC d0
INVALID MAC d0
INVALID MAC d0
INVALID MAC a
INVALID MAC a000000001
INVALID MAC a000000002
INVALID MAC a000000003
INVALID MAC a000000004
INVALID MAC a000000005
INVALID MAC a000000006

It also does not show the DHCP server and Scope it came from.

I appreciate your help !
0
 
LVL 5

Expert Comment

by:torvir
ID: 34980397
I think you should do the last match like this
([a-f0-9]*)
Otherwise it only matches a letter a-f followed by numbers. There will be a-f at random places in the real mac-addresses
so here is the revised match row:

if (/Dhcp Server (\d+\.\d+\.\d+\.\d+) Scope (\d+\.\d+\.\d+\.\d+) Add reservedip (\d+\.\d+\.\d+\.\d+) ([a-f0-9]*)/)

0
 
LVL 5

Expert Comment

by:torvir
ID: 34980427
You could easy change the script to show whatever you want.

$1 is the DHCP server¨
$2 is the scope

change to
print "INVALID MAC $4 from DHCP server $1 scope $2\n";
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 34980437
Adjusting this to pass the file to the script would be trivial.
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

while ( <DATA> ){
    my ($dhcp_srv, $scope, $ip, $mac, $host) = (split(/\s/, $_))[2,4,7,8,9];
    if ( length($mac) != 12 ) {
        # output your log entry as needed
        print Dumper($dhcp_srv, $scope, $ip, $mac, $host), $/;
    }
}

__DATA__
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.152 0002a56b94ce "stvfntest.bhmstv.help.corp" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.153 0a0a0a0a000a "aixtest1" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.154 0a0a0a0a000b "aixtest2" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.155 000c2903fdfd "LinuxIMG" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.156 a000000001 "VS_MGMT_336" "" ""
Dhcp Server 10.104.164.112 Scope 10.104.164.0 Add reservedip 10.104.165.157 a000000002 "VS_MGMT_352" "" ""

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 34980525
Hi FishMonger !

I created a file named make_netsh_log.pl

I then ran it  as

$ ./make_netsh_log.pl  merged.netsh

Name "main::DATA" used only once: possible typo at ./make_netsh_log.pl line 7.
readline() on unopened filehandle DATA at ./make_netsh_log.pl line 7.

What did I miss?

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

while ( <DATA> ){
    my ($dhcp_srv, $scope, $ip, $mac, $host) = (split(/\s/, $_))[2,4,7,8,9];
    if ( length($mac) != 12 ) {
        # output your log entry as needed
        print Dumper($dhcp_srv, $scope, $ip, $mac, $host), $/;
    }
}

Open in new window

0
 
LVL 24

Expert Comment

by:mankowitz
ID: 34980567
ok, some modification:

while (<>)
{
if (/Dhcp Server (\d+\.\d+\.\d+\.\d+) Scope (\d+\.\d+\.\d+\.\d+) Add reservedip (\d+\.\d+\.\d+\.\d+) ([a-f0-9]*)/i)
{
if (length($4)<12)
{
print "INVALID MAC $4 DHCP $1 Scope $2 ReservedIP 3\n";

}

}

}
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 34980578
Added scope, server and reserved IP

while (<>)
{
   if (/Dhcp Server (\d+\.\d+\.\d+\.\d+) Scope (\d+\.\d+\.\d+\.\d+) Add reservedip (\d+\.\d+\.\d+\.\d+) ([a-f0-9]*)/i)
   {
   if (length($4)<12)
      {
         print "INVALID MAC $4 DHCP $1 Scope $2 ReservedIP 3\n";
      }
   }
}

Open in new window

0
 
LVL 28

Expert Comment

by:FishMonger
ID: 34980580
Change:
while ( <DATA> ){


to:
while ( <> ){
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 34980604
For production scripts I'd actually open a filehandle and add error handling, but these posts are just to jet you started.
0
 
LVL 1

Author Comment

by:richsark
ID: 34980658
Hi Mankowitz,

I ran above, looks good so far :)

$ perl make2.pl merged.netsh

INVALID MAC 01 DHCP 10.104.132.110 Scope 10.104.140.0 ReservedIP 3
INVALID MAC 01 DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 3

So maybe a report like
INVALID MAC "01" for host "Moxa119" DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 3


Can we also get the hostname in there?
Dhcp Server 10.104.132.110 Scope 10.104.140.0 Add reservedip 10.104.143.180 01 "Moxa119" "" ""
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 28

Expert Comment

by:FishMonger
ID: 34980699

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

unless ( @ARGV ) { die "useage: $0 <filename>\n"; }

open my $fh, '<', $ARGV[0] or die "failed to open '$ARGV[0] $!";

while ( my $line = <$fh> ){
    my ($dhcp_srv, $scope, $ip, $mac, $host) = (split(/\s/, $line))[2,4,7,8,9];
    
    if ( length($mac) != 12 ) {
        print "INVALID MAC:$mac for host:$host DHCP:$dhcp_srv Scope:$scope Reserved IP:$ip\n";
    }
}

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 34980752
Hi Fishmonger,

I ran your revised code: got this

$ ./fish.pl merged.netsh
Use of uninitialized value $mac in length at ./fish.pl line 14, <$fh> line 1.
Use of uninitialized value $mac in concatenation (.) or string at ./fish.pl line 15, <$fh> line 1.
Use of uninitialized value $host in concatenation (.) or string at ./fish.pl line 15, <$fh> line 1.
Use of uninitialized value $dhcp_srv in concatenation (.) or string at ./fish.pl line 15, <$fh> line 1.
Use of uninitialized value $scope in concatenation (.) or string at ./fish.pl line 15, <$fh> line 1.
Use of uninitialized value $ip in concatenation (.) or string at ./fish.pl line 15, <$fh> line 1.
INVALID MAC: for host: DHCP: Scope: Reserved IP:
Use of uninitialized value $mac in length at ./fish.pl line 14, <$fh> line 2.
Use of uninitialized value $mac in concatenation (.) or string at ./fish.pl line 15, <$fh> line 2.
Use of uninitialized value $host in concatenation (.) or string at ./fish.pl line 15, <$fh> line 2.
Use of uninitialized value $dhcp_srv in concatenation (.) or string at ./fish.pl line 15, <$fh> line 2.
Use of uninitialized value $scope in concatenation (.) or string at ./fish.pl line 15, <$fh> line 2.
Use of uninitialized value $ip in concatenation (.) or string at ./fish.pl line 15, <$fh> line 2.
INVALID MAC: for host: DHCP: Scope: Reserved IP:
Use of uninitialized value $mac in length at ./fish.pl line 14, <$fh> line 3.
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 34980769
while (<>)
{
   if (/Dhcp Server (\d+\.\d+\.\d+\.\d+) Scope (\d+\.\d+\.\d+\.\d+) Add reservedip (\d+\.\d+\.\d+\.\d+) ([a-f0-9]*)\s"[^"]*"/i)
   {
   if (length($4)<12)
      {
         print "INVALID MAC \"$4\" for host \"$5\" DHCP $1 Scope $2 ReservedIP $3\n";
      }
   }
}

Open in new window

0
 
LVL 28

Expert Comment

by:FishMonger
ID: 34980776
Your merged.netsh file is not formatted like the sample data you posted.

Here's the output I get using the data and format that you posted.

E:\TEMP\test>perl-1.pl merged.netsh
INVALID MAC:a000000001 for host:"VS_MGMT_336" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.156
INVALID MAC:a000000002 for host:"VS_MGMT_352" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.157
0
 
LVL 1

Author Comment

by:richsark
ID: 34980820
Hi Fishmonger,

Odd?? I have attached the full file merged.netsh.txt
0
 
LVL 1

Author Comment

by:richsark
ID: 34980974
Hello mankowitz: I ran your code as


$ perl make2.pl merged.netsh.txt
INVALID MAC "01" for host "" DHCP 10.104.132.110 Scope 10.104.140.0 ReservedIP 10.104.143.180
INVALID MAC "01" for host "" DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 10.104.164.91
INVALID MAC "a000000001" for host "" DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 10.104.165.156
INVALID MAC "a000000002" for host "" DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 10.104.165.157
INVALID MAC "a000000003" for host "" DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 10.104.165.158
INVALID MAC "a000000004" for host "" DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 10.104.165.159
INVALID MAC "a000000005" for host "" DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 10.104.165.160
INVALID MAC "a000000006" for host "" DHCP 10.104.164.112 Scope 10.104.164.0 ReservedIP 10.104.165.161

For the host its only ""?
while (<>)
{
   if (/Dhcp Server (\d+\.\d+\.\d+\.\d+) Scope (\d+\.\d+\.\d+\.\d+) Add reservedip (\d+\.\d+\.\d+\.\d+) ([a-f0-9]*)\s"[^"]*"/i)
   {
   if (length($4)<12)
      {
         print "INVALID MAC \"$4\" for host \"$5\" DHCP $1 Scope $2 ReservedIP $3\n";
      }
   }
}

Open in new window

0
 
LVL 28

Expert Comment

by:FishMonger
ID: 34980986
As I stated, your file is not formatted the same, meaning you have blank lines and comments and other lines with similar, but not the exact same format as the ones you previously posted.

You could either use the regex that others have shown or you could add additional checks to the split approach.  I don't have time right now to make the adjustments to the script, but since you've posted over 40 other Perl questions here as well as on other forums that I follow, I think you should now have enough Perl knowledge to make some adjustments on your own.
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 34981234
while (<>)
{
   if (/Dhcp Server (\d+\.\d+\.\d+\.\d+) Scope (\d+\.\d+\.\d+\.\d+) Add reservedip (\d+\.\d+\.\d+\.\d+) ([a-f0-9]*)\s"([^"]*)"/i)
   {
   if (length($4)<12)
      {
         print "INVALID MAC \"$4\" for host \"$5\" DHCP $1 Scope $2 ReservedIP $3\n";
      }
   }
}

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 34981436
Thanks mankowitz, It worked !

Would it be hard to report a line saying " No Issues Found" if the file is ok?

Again Much appericated
0
 
LVL 24

Assisted Solution

by:mankowitz
mankowitz earned 200 total points
ID: 34982507
that's pretty easy.

$issues=0;
while (<>)
{
   if (/Dhcp Server (\d+\.\d+\.\d+\.\d+) Scope (\d+\.\d+\.\d+\.\d+) Add reservedip (\d+\.\d+\.\d+\.\d+) ([a-f0-9]*)\s"([^"]*)"/i)
   {
   if (length($4)<12)
      {
         print "INVALID MAC \"$4\" for host \"$5\" DHCP $1 Scope $2 ReservedIP $3\n";
         $issues=1;
      }
   }
}

if ($issues==0) { print "no issues found."; }

Open in new window

0
 
LVL 11

Expert Comment

by:tel2
ID: 34985306
Or, slightly more concisely:
...
}
print "No Issues Found.\n" unless $issues;
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 300 total points
ID: 34989955
Here's the adjusted version that uses split instead of the regex.

And this one catches invalid mac addresses which mankowitz's version misses.
D:\perl>richsark.pl merged.netsh
INVALID MAC:01 for host:"Moxa119" DHCP:10.104.132.110 Scope:10.104.140.0 Reserved IP:10.104.143.180
INVALID MAC:01 for host:"Sun" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.164.91
INVALID MAC:a000000001 for host:"VS_MGMT_336" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.156
INVALID MAC:a000000002 for host:"VS_MGMT_352" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.157
INVALID MAC:a000000003 for host:"Vs_onstore DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.158
INVALID MAC:a000000004 for host:"Vs_onstore DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.159
INVALID MAC:a000000005 for host:"Vs_onstore DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.160
INVALID MAC:a000000006 for host:"Vs_onstore DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.161
INVALID MAC:0a for host:"stvdc02" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.167.197
INVALID MAC:1a for host:"rack DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.164.17
INVALID MAC:01ab for host:"switch DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.164.18
INVALID MAC:01ac for host:"switch DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.164.19
INVALID MAC:1abc for host:"STVWVCTR" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.166.50
INVALID MAC:0f for host:"FV-REC01" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.166.30
INVALID MAC:01ae23 for host:"STVLEBGW" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.164.78
INVALID MAC:a123 for host:"AHSBHMNBU01 DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.166.81
INVALID MAC:0a23 for host:"STVLEGBW DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.166.80
INVALID MAC:1a67 for host:"STVWBGIAPP" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.164.116
INVALID MAC:1a45 for host:"STVWBGIDB" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.164.117
INVALID MAC:1a23 for host:"STVWHLTHVLT" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.166.34
INVALID MAC:1a24 for host:"stvwcensibuf" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.164.153
INVALID MAC:01a2bc for host:"STVWDC04" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.166.35
INVALID MAC:1a25 for host:"STVWBGITEST" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.166.37
INVALID MAC:1a26 for host:"EHSWDC01" DHCP:10.104.164.112 Scope:10.104.164.0 Reserved IP:10.104.165.208
INVALID MAC:01372b84fc for host:"4mor-ad625758" DHCP:10.104.164.112 Scope:10.104.168.0 Reserved IP:10.104.168.172
INVALID MAC:d152 for host:"Pixsys" DHCP:10.104.164.112 Scope:10.104.168.0 Reserved IP:10.104.168.30
INVALID MAC:02 for host:"PainLabMoxa" DHCP:10.104.164.112 Scope:10.104.172.0 Reserved IP:10.104.174.120
INVALID MAC:01 for host:"4MPACUMOXA" DHCP:10.104.164.112 Scope:10.104.172.0 Reserved IP:10.104.174.123
INVALID MAC:0c39174184 for host:"Pyxis DHCP:10.104.164.112 Scope:10.104.172.0 Reserved IP:10.104.174.184
INVALID MAC:0a for host:"em41 DHCP:10.104.164.112 Scope:10.104.172.0 Reserved IP:10.104.172.36
INVALID MAC:0d76 for host:"Pixsys DHCP:10.104.164.112 Scope:10.104.172.0 Reserved IP:10.104.174.191
INVALID MAC:1a23 for host:"Pyxis DHCP:10.104.164.112 Scope:10.104.172.0 Reserved IP:10.104.172.61
INVALID MAC:0a for host:"mceit116290" DHCP:10.104.164.112 Scope:10.104.180.0 Reserved IP:10.104.180.191
INVALID MAC:0aa0180089 for host:"HR DHCP:10.104.164.112 Scope:10.104.180.0 Reserved IP:10.104.180.89
INVALID MAC:0aa0180090 for host:"printer" DHCP:10.104.164.112 Scope:10.104.180.0 Reserved IP:10.104.180.90
INVALID MAC:00802501c1 for host:"WatchCild DHCP:10.104.164.112 Scope:10.104.184.0 Reserved IP:10.104.186.87
INVALID MAC:01 for host:"MoxaOSC" DHCP:10.104.164.112 Scope:10.104.204.0 Reserved IP:10.104.206.210
INVALID MAC:02 for host:"MoxaNeuroSur" DHCP:10.104.164.112 Scope:10.104.204.0 Reserved IP:10.104.206.211
INVALID MAC:03 for host:"Moxa3BS" DHCP:10.104.164.112 Scope:10.104.204.0 Reserved IP:10.104.206.212
INVALID MAC:756e3a0016d3baed3f for host:"7B1CE-AE837894.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.227
INVALID MAC:756e3a002170e67d34 for host:"2dpcat-af194024" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.230
INVALID MAC:756e3a00042371dff3 for host:"STV-TAB-FC01.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.200
INVALID MAC:756e3a000e35ab52ea for host:"stv-fsnt2.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.201
INVALID MAC:756e3a000e35ab4a02 for host:"stv-fsnt4.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.202
INVALID MAC:756e3a000e35ab487b for host:"stv-fsnt1.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.203
INVALID MAC:756e3a00097c5fce8c for host:"stvcart1.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.204
INVALID MAC:756e3a00097ca8ee03 for host:"STVCART3.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.205
INVALID MAC:756e3a0007eb314fd8 for host:"STVCART4.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.206
INVALID MAC:756e3a000e35ab35cc for host:"stv-fsnt3.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.207
INVALID MAC:756e3a00097c7789d6 for host:"STVCART2.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.208
INVALID MAC:756e3a000cf133a413 for host:"3wnsa-ad5517074" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.210
INVALID MAC:756e3a000423784068 for host:"CLNEXTAB3.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.211
INVALID MAC:756e3a00042371dec8 for host:"STV-FC08.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.212
INVALID MAC:756e3a000423784181 for host:"7B1CE-AD518028.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.213
INVALID MAC:756e3a000423784319 for host:"7B1CE-AD517272.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.214
INVALID MAC:756e3a00042371dfcf for host:"CLNEXTAB5.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.215
INVALID MAC:756e3a0004237881d6 for host:"7B1CE-AD518029.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.216
INVALID MAC:756e3a001b7766a583 for host:"CLINEX-AE837901.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.222
INVALID MAC:756e3a001f3aa48e73 for host:"CSCTST-AF148813.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.223
INVALID MAC:756e3a001b7766ad53 for host:"CLINEX-AD837895.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.224
INVALID MAC:756e3a001b775a5cd9 for host:"CLINEX-AD837912.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.225
INVALID MAC:756e3a0016e32c0f68 for host:"Stv-fsnt5.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.209
INVALID MAC:756e3a0018de3e77cf for host:"him-ae282234" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.228
INVALID MAC:756e3a001c2697bdff for host:"CLNEXC-AE942947.bhmstv.ascensionhealth.corp" DHCP:10.104.164.112 Scope:192.168.28.0 Reserved IP:192.168.29.229

Open in new window

#!/usr/bin/perl

use strict;
use warnings;

unless ( @ARGV ) { die "useage: $0 <filename>\n"; }

open my $fh, '<', $ARGV[0] or die "failed to open '$ARGV[0]' $!";

my $problems;
while ( my $line = <$fh> ) {

    next if $line !~ /reservedip/;
    
    my ($dhcp_srv, $scope, $ip, $mac, $host) = (split(/\s/, $line))[2,4,7,8,9];
    
    if ( length($mac) != 12 ) {
        print "INVALID MAC:$mac for host:$host DHCP:$dhcp_srv Scope:$scope Reserved IP:$ip\n";
        $problems++;
    }
}
close $fh;

print "No Issues Found.\n" unless $problems;

Open in new window

0
 
LVL 1

Author Closing Comment

by:richsark
ID: 34993951
Thanks to all Fishmonger and to Mankowitz
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now