0

The below function is an IP scanner and returns a list of IP addresses and MAC addresses. I am trying to figure out how to filter out only MAC addresses that contains a specific vendor.

For example, I'm trying to filter the list to only capture IP/MAC that contains 'AA:BB:CC'.

Can anyone point me in the right direction?

def scan(ip):
    arp_packet = scapy.ARP(pdst=ip)
    broadcast_packet = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_broadcast_packet = broadcast_packet/arp_packet
    answered_list = scapy.srp(arp_broadcast_packet, timeout=1, verbose=False)[0]
    client_list = []

    for element in answered_list:
        client_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc}
        client_list.append(client_dict)


    return client_list
deceze
  • 510,633
  • 85
  • 743
  • 889
Alex
  • 5

1 Answers1

1

If you want to check if the string contains the pattern, use find():

pattern = 'AA:BB:CC'
if mac.find( pattern ) != -1 :
    pass  # found!

If you want to check if the string has the pattern at the beginning:

pattern = 'AA:BB:CC'
if mac.startswith( pattern ) :
    pass  # found!
lenik
  • 23,228
  • 4
  • 34
  • 43