【问题标题】:How to get network interface speed programactically on Linux?如何在 Linux 上以编程方式获得网络接口速度?
【发布时间】:2009-06-11 15:38:23
【问题描述】:

我想知道网络连接信息中显示的速度,例如100Mb/s、10Mb/s,不是可用带宽。提前致谢!

【问题讨论】:

    标签: linux networking performance


    【解决方案1】:

    如果您想在 C 代码中执行此操作,请查找 mii-tool.c

    【讨论】:

    • 信息是通过查询适当的 ioctl 函数完成的,mii-tool.c 提供了这方面的示例。
    【解决方案2】:

    发现于http://linuxhelp.blogspot.com/2005/10/find-speed-of-your-ethernet-card-in.html

    以编程方式读取此信息并解析它,寻找 100baseTx 或类似的

    # mii-tool -v eth0
    eth0: negotiated 100baseTx-FD flow-control, link ok
      product info: vendor 00:00:20, model 32 rev 1
      basic mode:   autonegotiation enabled
      basic status: autonegotiation complete, link ok
      capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
      advertising:  100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
      link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
    

    另外,在同一篇文章中,您可以使用它并查找“速度:”行

    #ethtool eth0
    
    Settings for eth0:
      Supported ports: [ TP MII ]
      Supported link modes:   10baseT/Half 10baseT/Full
                              100baseT/Half 100baseT/Full
      Supports auto-negotiation: Yes
      Advertised link modes:  10baseT/Half 10baseT/Full
                              100baseT/Half 100baseT/Full
      Advertised auto-negotiation: Yes
      Speed: 100Mb/s
      Duplex: Full
      Port: MII
      PHYAD: 32
      Transceiver: internal
      Auto-negotiation: on
      Supports Wake-on: pumbg
      Wake-on: p
      Current message level: 0x00000007 (7)
      Link detected: yes
    

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-29
      • 1970-01-01
      • 2011-02-21
      相关资源
      最近更新 更多