---
# System prepended metadata

title: 'Get mac address from /net files, Ubuntu only'

---

# Get mac address from /net files, Ubuntu only

```python
def get_mac_address_ubuntu():
    final_iface = None
    final_mac = None
    net_route_filepath = "/proc/net/route"
    try:
        with open(net_route_filepath) as f:
            iface_data = f.read()
        for line in iface_data.split("\n")[1:-1]:
            iface_name, dest = line.split("\t")[:2]
            if dest == "00000000":
                final_iface = iface_name
    except:
        logging.debug("Could not find file: '%s'", filepath)
        return None
        
    filepath_net_class = "/sys/class/net/" + iface_name + "/address"
    try:
        with open(filepath_net_class) as f:
            net_data = f.read()
            final_mac= net_data
    except (OSError, IOError): 
        logging.debug("Could not find file: '%s'", filepath)
        
    return final_mac
```