【问题标题】:linux ethernet drivers product id, device id and addresslinux 以太网驱动程序产品 ID、设备 ID 和地址
【发布时间】:2015-07-15 17:48:47
【问题描述】:

在 linux 平台上,我需要从 cli 中找到给定名称的接口的 product_id、vendor_id 和地址。我正在使用以下命令来查找它:

# to find addr:
pci_interface_addr0=$(ethtool -i $eth0 | grep -i bus-info | tail -c 8)

# to find ids:
complete_id=$(lspci -nvv | grep $pci_interface_addr0 | awk '{print $3}')
vendor_id=$(echo $complete_id | cut -d \: -f 1)
product_id=$(echo $complete_id | cut -d \: -f 2)

有没有更好的方法来解决这个问题?因为我有像上面的 tail -c 8 这样的硬编码值。

这可以在python中完成吗?由于父程序主要是一个python模块。

感谢任何好的输入!

【问题讨论】:

    标签: python linux bash awk ethernet


    【解决方案1】:

    有没有更好的方法来解决这个问题?

    我会利用通常位于/syssysfs 文件系统。例如,给定我系统上的接口名称enp0s25,我可以在以下位置找到供应商:

    $ cat /sys/class/net/enp0s25/device/vendor
    0x8086
    

    产品ID在:

    $ cat /sys/class/net/enp0s25/device/device 
    0x1502
    

    同一目录中的uevent 文件包含此信息,其格式可以很容易地导入到 shell 脚本中:

    $ cat /sys/class/net/enp0s25/device/uevent
    DRIVER=e1000e
    PCI_CLASS=20000
    PCI_ID=8086:1502
    PCI_SUBSYS_ID=17AA:21F3
    PCI_SLOT_NAME=0000:00:19.0
    MODALIAS=pci:v00008086d00001502sv000017AAsd000021F3bc02sc00i00
    

    【讨论】:

    • 谢谢@larsks!更清洁的方法
    • 我很高兴它有帮助。您可能需要花点时间单击此答案左侧的复选标记;这既是一种表达“谢谢”的方式,也是一种让其他人知道您的问题已得到解答的方式。
    猜你喜欢
    • 1970-01-01
    • 2014-07-09
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多