Get Up AND Down Network Interface MAC Addresses on Linux - Unix

This is a discussion on Get Up AND Down Network Interface MAC Addresses on Linux - Unix ; I want to get the MAC address of all the network cards on the system. This includes network interfaces that are not running (down). All the solutions I've seen only work for the running network cards. I know it must ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Get Up AND Down Network Interface MAC Addresses on Linux

  1. Get Up AND Down Network Interface MAC Addresses on Linux

    I want to get the MAC address of all the network cards on the system.
    This includes network interfaces that are not running (down).
    All the solutions I've seen only work for the running network cards.
    I know it must be possible because ifconfig -a is able to do it - I've
    tried to get an idea from the source code but it is hard to follow.
    Neither do I want to exec ifconfig.

    Any ideas?

    Thanks in advance.

    Tim.

  2. Re: Get Up AND Down Network Interface MAC Addresses on Linux

    Tim wrote:

    > I want to get the MAC address of all the network cards on the system.
    > This includes network interfaces that are not running (down).
    > All the solutions I've seen only work for the running network cards.
    > I know it must be possible because ifconfig -a is able to do it - I've
    > tried to get an idea from the source code but it is hard to follow.
    > Neither do I want to exec ifconfig.
    >
    > Any ideas?


    (ifconfig is deprecated.)

    strace ip link

    [...]
    socket(PF_NETLINK, SOCK_RAW, 0) = 3
    setsockopt(3, SOL_SOCKET, SO_SNDBUF, [32768], 4) = 0
    setsockopt(3, SOL_SOCKET, SO_RCVBUF, [32768], 4) = 0
    bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
    getsockname(3, {sa_family=AF_NETLINK, pid=909, groups=00000000}, [12]) = 0
    time(NULL) = 1204715959
    sendto(3, "\24\0\0\0\22\0\1\3\270\201\316G\0\0\0\0\21\0\0\0", 20, 0,
    {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
    recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0,
    groups=00000000},
    msg_iov(1)=[{"\374\0\0\0\20\0\2\0\270\201\316G\215\3\0\0\0\0\1
    \0\1\0"..., 16384}], msg_controllen=0, msg_flags=0}, 0) = 1000
    brk(0) = 0x806c000
    brk(0x808d000) = 0x808d000
    recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0,
    groups=00000000},
    msg_iov(1)=[{"\24\0\0\0\3\0\2\0\270\201\316G\215\3\0\0\0\0\0\0\1 \0\0"...,
    16384}], msg_controllen=0, msg_flags=0}, 0) = 20
    fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
    0) = 0xb7f80000
    socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
    ioctl(4, SIOCGIFTXQLEN, 0xbf94ba00) = 0
    close(4) = 0
    [...]

    Regards.

+ Reply to Thread