Linux 获取网口详细信息

一般来说,研究 ifconfig.c 源代码就可以达到目的了。


但是Linux已经提供了比较方便的获取网口信息的方式:


[philip@catonbj ~]$ cat /sys/class/net/em1/statistics/rx_bytes 
3911191274


在/sys/class/net/INTERFACE/statistics/ 目录下有所有网口的状态:

[philip@catonbj statistics]$ ls
collisions  rx_bytes       rx_crc_errors  rx_errors       rx_frame_errors   rx_missed_errors  rx_packets         tx_bytes           tx_compressed  tx_errors       tx_heartbeat_errors  tx_window_errors
multicast   rx_compressed  rx_dropped     rx_fifo_errors  rx_length_errors  rx_over_errors    tx_aborted_errors  tx_carrier_errors  tx_dropped     tx_fifo_errors  tx_packets


而它的上一级:

[philip@catonbj em1]$ ls
addr_assign_type  address  addr_len  broadcast  carrier  device  dev_id  dormant  duplex  flags  ifalias  ifindex  iflink  link_mode  mtu  netdev_group  operstate  power  queues  speed  statistics  subsystem  tx_queue_len  type  uevent



也有较详细的描述。


程序上或许获取接口比较难用,何不直接调用 cat 句柄调用呢?


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值