10

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.

RyPeck
  • 7,830
  • 3
  • 38
  • 58
Aviran
  • 5,160
  • 7
  • 44
  • 76

3 Answers3

11

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.

Cukic0d
  • 5,111
  • 2
  • 19
  • 48
Koreth
  • 681
  • 5
  • 15
2

You can easily by:

from scapy.all import Ether
print(Ether().src)

This prints the MAC address of the default interface you're using.

rockikz
  • 586
  • 1
  • 6
  • 17
-1

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'}]}

http://alastairs-place.net/projects/netifaces/

RyPeck
  • 7,830
  • 3
  • 38
  • 58