Link to home
Start Free TrialLog in
Avatar of Rich Rumble
Rich RumbleFlag for United States of America

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.10.0.151.14 = STRING: 0:5:5b:8e:5c:40
.1.3.6.1.2.1.4.22.1.2.23.10.1.11.240 = STRING: 0:5:5b:38:66:0c
.1.3.6.1.2.1.4.22.1.2.23.10.1.11.254 = STRING: 0:6:5b:8e:14:17
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.202 = STRING: 0:c0:d0:ea:36:49
.1.3.6.1.2.1.4.22.1.2.24.10.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


ASKER CERTIFIED SOLUTION
Avatar of ps15
ps15

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rich Rumble

ASKER

Thanks for the quick reply, however I'm not seeing the IP being printed on the output, here is what I have:
 cat file1.txt
.1.3.6.1.2.1.17.4.3.1.1.0.0.12.7.172.8 = Hex-STRING: 00 00 0C 07 AC 08
.1.3.6.1.2.1.17.4.3.1.1.0.3.50.168.20.0 = Hex-STRING: 00 03 32 A8 14 00
.1.3.6.1.2.1.17.4.3.1.1.0.6.91.56.114.187 = Hex-STRING: 00 06 5B 38 72 BB
.1.3.6.1.2.1.17.4.3.1.1.0.176.208.73.32.202 = Hex-STRING: 00 B0 D0 49 20 CA
.1.3.6.1.2.1.17.4.3.1.1.0.176.208.73.68.99 = Hex-STRING: 00 B0 D0 49 44 63
.1.3.6.1.2.1.17.4.3.1.1.0.176.208.73.68.130 = Hex-STRING: 00 B0 D0 49 44 82
.1.3.6.1.2.1.17.4.3.1.1.0.176.208.73.68.228 = Hex-STRING: 00 B0 D0 49 44 E4
.1.3.6.1.2.1.17.4.3.1.1.0.176.208.73.139.137 = Hex-STRING: 00 B0 D0 49 8B 89
.1.3.6.1.2.1.17.4.3.1.1.0.208.183.142.235.150 = Hex-STRING: 00 D0 B7 8E EB 96
.1.3.6.1.2.1.17.4.3.1.1.0.224.129.43.118.231 = Hex-STRING: 00 E0 81 2B 76 E7

 cat file2.txt
.1.3.6.1.2.1.17.4.3.1.2.0.0.12.7.172.8 = INTEGER: 1
.1.3.6.1.2.1.17.4.3.1.2.0.3.50.168.20.0 = INTEGER: 152
.1.3.6.1.2.1.17.4.3.1.2.0.6.91.56.114.187 = INTEGER: 361
.1.3.6.1.2.1.17.4.3.1.2.0.176.208.73.32.202 = INTEGER: 262
.1.3.6.1.2.1.17.4.3.1.2.0.176.208.73.68.99 = INTEGER: 261
.1.3.6.1.2.1.17.4.3.1.2.0.176.208.73.68.130 = INTEGER: 259
.1.3.6.1.2.1.17.4.3.1.2.0.176.208.73.68.228 = INTEGER: 357
.1.3.6.1.2.1.17.4.3.1.2.0.176.208.73.139.137 = INTEGER: 1
.1.3.6.1.2.1.17.4.3.1.2.0.208.183.142.235.150 = INTEGER: 1
.1.3.6.1.2.1.17.4.3.1.2.0.224.129.43.118.231 = INTEGER: 1

 cat file3.txt
.1.3.6.1.2.1.17.1.4.1.2.1 = INTEGER: 422
.1.3.6.1.2.1.17.1.4.1.2.152 = INTEGER: 240
.1.3.6.1.2.1.17.1.4.1.2.259 = INTEGER: 278
.1.3.6.1.2.1.17.1.4.1.2.261 = INTEGER: 280
.1.3.6.1.2.1.17.1.4.1.2.262 = INTEGER: 281
.1.3.6.1.2.1.17.1.4.1.2.357 = INTEGER: 408
.1.3.6.1.2.1.17.1.4.1.2.361 = INTEGER: 412

 cat file4.txt
.1.3.6.1.2.1.31.1.1.1.1.422 = STRING: 1/1
.1.3.6.1.2.1.31.1.1.1.1.240 = STRING: 3/24
.1.3.6.1.2.1.31.1.1.1.1.278 = STRING: 5/3
.1.3.6.1.2.1.31.1.1.1.1.280 = STRING: 5/5
.1.3.6.1.2.1.31.1.1.1.1.281 = STRING: 5/6
.1.3.6.1.2.1.31.1.1.1.1.408 = STRING: 6/37
.1.3.6.1.2.1.31.1.1.1.1.412 = STRING: 6/41

cat file5.txt
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.6 = STRING: 0:0:C:7:AC:8
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.26 = STRING: 0:3:32:A8:14:0
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.206 = STRING: 0:6:5B:38:72:BB
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.16 = STRING: 0:B0:D0:49:20:CA
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.20 = STRING: 0:B0:D0:49:44:63
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.246 = STRING: 0:B0:D0:49:44:82
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.216 = STRING: 0:B0:D0:49:44:E4
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.208 = STRING: 0:B0:D0:49:8B:89
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.209 = STRING: 0:D0:B7:8E:EB:96
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.209 = STRING: 0:E0:81:2B:76:E7

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
the case's in file5.txt are actually lowercase...
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.6 = STRING: 0:0:C:7:ac:8
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.26 = STRING: 0:3:32:a8:14:0
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.206 = STRING: 0:6:5b:38:72:bb
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.16 = STRING: 0:b0:d0:49:20:ca
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.20 = STRING: 0:b0:d0:49:44:63
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.246 = STRING: 0:b0:d0:49:44:82
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.216 = STRING: 0:b0:d0:49:44:e4
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.208 = STRING: 0:b0:d0:49:8B:89
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.209 = STRING: 0:d0:b7:8e:eb:96
.1.3.6.1.2.1.4.22.1.2.24.10.0.25.209 = STRING: 0:e0:81:2b:76:e7
-rich
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
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