Rich Rumble
asked on
Match IP address to Mac Address
In this question: https://www.experts-exchange.com/questions/21846607/Pattern-matching-and-Parsing.html I asked for a script that helped me match mac address on a cisco catalyst switch to it's switch port. I'd now like to match the same mac address's to their ip address.
The output of the mac-to-sw_port looks like this:
Mac address= 00 05 5B 8E 5C 40 port=5/29
Mac address= 00 05 5B 38 66 0C port=1/1
Mac address= 00 06 5B 8E 14 17 port=7/24
Mac address= 00 C0 D0 EA 36 49 port=4/12
Mac address= 00 C0 D0 49 8B AD port=1/1
The data for the mac to ip looks like this:
.1.3.6.1.2.1.4.22.1.2.23.1 0.0.151.14 = STRING: 0:5:5b:8e:5c:40
.1.3.6.1.2.1.4.22.1.2.23.1 0.1.11.240 = STRING: 0:5:5b:38:66:0c
.1.3.6.1.2.1.4.22.1.2.23.1 0.1.11.254 = STRING: 0:6:5b:8e:14:17
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.202 = STRING: 0:c0:d0:ea:36:49
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.206 = STRING: 0:c0:d0:49:8b:ad
This portion can be ignored/chomped .1.3.6.1.2.1.4.22.1.2.24.
The ip address follows the chomped portion. Also note that LEADING 0's are dropped, so the mac addres of "0:6:5b:8e:14:17" is actually 00:06:5b:8e:14:17
I'm not sure if it's possible or easier to use the previous script linked above, to add a line that looks for "file5" that would contain the ip to mac strings above, and output like this:
Mac address= 00 C0 D0 EA 36 49 port=4/12 IP= 10.0.25.202
Mac address= 00 05 5B 38 66 0C port=1/1 IP = 10.1.11.240
-rich
The output of the mac-to-sw_port looks like this:
Mac address= 00 05 5B 8E 5C 40 port=5/29
Mac address= 00 05 5B 38 66 0C port=1/1
Mac address= 00 06 5B 8E 14 17 port=7/24
Mac address= 00 C0 D0 EA 36 49 port=4/12
Mac address= 00 C0 D0 49 8B AD port=1/1
The data for the mac to ip looks like this:
.1.3.6.1.2.1.4.22.1.2.23.1
.1.3.6.1.2.1.4.22.1.2.23.1
.1.3.6.1.2.1.4.22.1.2.23.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
This portion can be ignored/chomped .1.3.6.1.2.1.4.22.1.2.24.
The ip address follows the chomped portion. Also note that LEADING 0's are dropped, so the mac addres of "0:6:5b:8e:14:17" is actually 00:06:5b:8e:14:17
I'm not sure if it's possible or easier to use the previous script linked above, to add a line that looks for "file5" that would contain the ip to mac strings above, and output like this:
Mac address= 00 C0 D0 EA 36 49 port=4/12 IP= 10.0.25.202
Mac address= 00 05 5B 38 66 0C port=1/1 IP = 10.1.11.240
-rich
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the case's in file5.txt are actually lowercase...
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.6 = STRING: 0:0:C:7:ac:8
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.26 = STRING: 0:3:32:a8:14:0
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.206 = STRING: 0:6:5b:38:72:bb
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.16 = STRING: 0:b0:d0:49:20:ca
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.20 = STRING: 0:b0:d0:49:44:63
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.246 = STRING: 0:b0:d0:49:44:82
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.216 = STRING: 0:b0:d0:49:44:e4
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.208 = STRING: 0:b0:d0:49:8B:89
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.209 = STRING: 0:d0:b7:8e:eb:96
.1.3.6.1.2.1.4.22.1.2.24.1 0.0.25.209 = STRING: 0:e0:81:2b:76:e7
-rich
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
-rich
ASKER
which fixed my issue for the most part... still there are 2 not showing up that should...
Mac address=00 00 0C 07 AC 08 port=1/1 IP =
Mac address=00 B0 D0 49 44 63 port=5/5 IP = 10.0.25.20
Mac address=00 03 32 A8 14 00 port=3/24 IP = 10.0.25.26
Mac address=00 B0 D0 49 8B 89 port=1/1 IP =
Mac address=00 B0 D0 49 20 CA port=5/6 IP = 10.0.25.16
Mac address=00 B0 D0 49 44 82 port=5/3 IP = 10.0.25.246
Mac address=00 E0 81 2B 76 E7 port=1/1 IP = 10.0.25.209
Mac address=00 B0 D0 49 44 E4 port=6/37 IP = 10.0.25.216
Mac address=00 06 5B 38 72 BB port=6/41 IP = 10.0.25.206
Mac address=00 D0 B7 8E EB 96 port=1/1 IP = 10.0.25.209
I'll check my files again, thanks again!
-rich
Mac address=00 00 0C 07 AC 08 port=1/1 IP =
Mac address=00 B0 D0 49 44 63 port=5/5 IP = 10.0.25.20
Mac address=00 03 32 A8 14 00 port=3/24 IP = 10.0.25.26
Mac address=00 B0 D0 49 8B 89 port=1/1 IP =
Mac address=00 B0 D0 49 20 CA port=5/6 IP = 10.0.25.16
Mac address=00 B0 D0 49 44 82 port=5/3 IP = 10.0.25.246
Mac address=00 E0 81 2B 76 E7 port=1/1 IP = 10.0.25.209
Mac address=00 B0 D0 49 44 E4 port=6/37 IP = 10.0.25.216
Mac address=00 06 5B 38 72 BB port=6/41 IP = 10.0.25.206
Mac address=00 D0 B7 8E EB 96 port=1/1 IP = 10.0.25.209
I'll check my files again, thanks again!
-rich
ASKER
I'll award the points now, its my fault (per usual) that the script didn't work ;) file5 still has some uppercase characters in it. Again I thank you for your time.
-rich
-rich
ASKER
cat file1.txt
.1.3.6.1.2.1.17.4.3.1.1.0.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.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
.1.3.6.1.2.1.4.22.1.2.24.1
Output:
./ip-mac-sp.pl
Mac address=00 00 0C 07 AC 08 port=1/1 IP =
Mac address=00 B0 D0 49 44 63 port=5/5 IP =
Mac address=00 03 32 A8 14 00 port=3/24 IP =
Mac address=00 B0 D0 49 8B 89 port=1/1 IP =
Mac address=00 B0 D0 49 20 CA port=5/6 IP =
Mac address=00 B0 D0 49 44 82 port=5/3 IP =
Mac address=00 E0 81 2B 76 E7 port=1/1 IP =
Mac address=00 B0 D0 49 44 E4 port=6/37 IP =
Mac address=00 06 5B 38 72 BB port=6/41 IP =
Mac address=00 D0 B7 8E EB 96 port=1/1 IP =
Ideas? Thanks!
-rich