Skip to content

get_mac_address returns None if there are no routes on the Linux system #78

@vlstill

Description

@vlstill

Describe the bug
If there are no routes on the system, the getmac.get_mac_address() returns None even if there are network interfaces.

This can happen e.g. in testing environments such as virtual machines and or inside Linux network namespaces, but in general in systems not connected to larger networks.

To Reproduce

Tested on Ubuntu 20.04LTS (under root)

$ ip netns add getmac-test
$ ip netns exec getmac-test ip link set dev lo up
$ ip netns exec getmac-test python
>>> import getmac
>>> getmac.get_mac_address() is None
True
>>> exit()
$ ip netns exec getmac-test ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

Expected behavior
A mac address is returned even without routes set.

System info
(please complete the following information):

  • OS name: Ubuntu 20.04LTS
  • Python version: 3.8.10

Additional context

none

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions