import netifaces print (netifaces.interfaces()) print (netifaces.ifaddresses('lo')) print (netifaces.AF_LINK) addrs = netifaces.ifaddresses('ens33') print(addrs[netifaces.AF_INET]) print(addrs[netifaces.AF_LINK]) code example
Example: python3 netifaces get current interface
>>> import netifaces
>>> def_gw_device = netifaces.gateways()['default'][netifaces.AF_INET][1]