How do I get the MAC address of the interface I am sending packets with?
I am trying to create a custom ARP packet, and I need to include my own MAC in it. I can not seem to find a way to get it.
Take a look at the get_if_hwaddr() function.
Doc: https://scapy.readthedocs.io/en/latest/routing.html
This code may help you :
my_macs = [get_if_hwaddr(i) for i in get_if_list()]
Cheers, K.
You can easily by:
from scapy.all import Ether
print(Ether().src)
This prints the MAC address of the default interface you're using.
The Netifaces Python Package provides a great amount of information about the interfaces you are working with.
>>> netifaces.ifaddresses('en0')
{18: [{'addr': '00:12:34:56:78:9a'}], 2: [{'broadcast':
'10.255.255.255', 'netmask': '255.0.0.0', 'addr': '10.16.1.4'}],
30: [{'netmask': 'ffff:ffff:ffff:ffff::', 'addr':
'fe80::123:4567:89ab:cdef%en0'}]}