是不是可以用Python实现
- import subprocess
- # 获取网络接口的 MAC 地址
- def get_mac_address(interface):
- result = subprocess.run(['ifconfig', interface], stdout=subprocess.PIPE)
- output = result.stdout.decode('utf-8')
- mac_address = output.split('ether ')[1].split(' ')[0]
- return mac_address
- # 为每个设备分配 NodeID
- devices = ['eth0', 'eth1']
- node_ids = {}
- for idx, dev in enumerate(devices):
- mac = get_mac_address(dev)
- node_ids[mac] = idx + 1 # 分配 NodeID
- print(node_ids)
|