-1

I have a dictionary with an IP address as the key and mac address as the value. One entry might look like this:

ip_dict['192.168.1.100'] = '33:22:11'

This dictionary is populated by reading the output of an arp table. What I am looking for is an ip address (the key) which has more than one mac address (the value). For each time I discover an ip with multiple values, I want to output an error showing the ip address and the list of mac addresses found.

Is there a simple way to do this?

Thanks for help.

--------------------------- Clarification ------------------------------------------

Sorry, it was late last night and wasn't thinking correctly.....

What I have is a mac dictionary with an ip address. There are no duplicate mac address. Each mac has a single ip address (value field). The question is which mac addresses have the same ip address?

Example:

mac_dict['11:22:33'] = '192.168.1.100'
mac_dict['11:23:44'] = '192.168.1.101'
mac_dict['11:23:43'] = '192.168.1.102'
mac_dict['12:43:55'] = '192.168.1.101'
mac_dict['54:22:65'] = '192.168.1.102'
mac_dict['21:1A:01'] = '192.168.1.101'

I'd like a way to generate a duplicate lists...

[('11':23:44', '12:43:55', '21:1A:01'), ('11:23:43', '54:22:65')]

The first three mac addresses all have 192.168.1.101 as their ip address, and the last two have 192.168.1.102 as their ip address. Because '11:22:33' is not duplicated, it doesn't appear in the list at all.

Thanks

3 Answers3

1
for key in ip_dict:
    if len(ip_dict[key]) > 1: #assuming the values are a list of mac address....
        print("IP has multiple mac addresses: {}".format(ip_dict[key]))
Josh Engelsma
  • 2,636
  • 14
  • 17
0
vals = set()
for k in ip_dict:
    v = ip_dict[k]
    if v in vals:
        print(k, 'is has a duplicate value')
    vals.add(v)
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
0

check this:

ip_dict[ip]=[mac1,mac2]
Nilesh
  • 20,521
  • 16
  • 92
  • 148
linbo
  • 2,393
  • 3
  • 22
  • 45