Python Glossary Русский

all Python 3uuidfunction

uuid.getnode()

generating UUIDs

Returns the network card's MAC address as a 48-bit integer; uuid1() and uuid6() take their node field from it.

Syntax

uuid.getnode() -> int

If no MAC can be found (a container, a sandbox), the function silently returns a random number with the multicast bit set — the least significant bit of the first octet; that bit is how you tell a stand-in from a real address. The first call can be slow: the module may launch an external program, then the result is cached. And it is the machine's address: UUIDs carrying it reveal which computer made them.

Examples

import uuid
node = uuid.getnode()
print(hex(node))  # → ? 0xa7b78c460531 — зависит от машины
print(0 <= node < 2 ** 48)  # → True
print((node >> 40) & 1)  # → ? 1 — значение случайное, MAC не найден

See also

Open in the full glossarydocs.python.orgReport an inaccuracy