Scapy - get my own MAC address

How to get the MAC address of the interface from which I send packets?

I am trying to create my own ARP package and I need to include my MAC in it. I can not find a way to get it.

+5
source share
3 answers

Take a look at the get_if_hwaddr () function.

This code can help you:

my_macs = [get_if_hwaddr(i) for i in get_if_list()] 

Cheers, K.

+8
source

You can easily:

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

This prints the MAC address of the default interface.

0
source

The Netifaces Python package provides a wealth of information about the interfaces you work 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/

-1
source

Source: https://habr.com/ru/post/1483925/


All Articles