使用python获取系统网络信息

psutil模块确实是运维工作中比较有用的模块,除了获取系统的硬件信息之外还能够获取到网络信息。

简单的测试如下:

In [8]: psutil.net_io_counters()

Out[8]: snetio(bytes_sent=40186207L, bytes_recv=620160806L, packets_sent=454876L, packets_recv=469843L, errin=0L, errout=0L, dropin=0L, dropout=0)


In [9]: psutil.net_io_counters(pernic = True

   ...: )

Out[9]: 

{'awdl0': snetio(bytes_sent=3121L, bytes_recv=0L, packets_sent=30L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'bridge0': snetio(bytes_sent=342L, bytes_recv=0L, packets_sent=1L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'en0': snetio(bytes_sent=0L, bytes_recv=0L, packets_sent=0L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'en1': snetio(bytes_sent=40969506L, bytes_recv=645656449L, packets_sent=469695L, packets_recv=486500L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'en2': snetio(bytes_sent=0L, bytes_recv=0L, packets_sent=0L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'en3': snetio(bytes_sent=0L, bytes_recv=0L, packets_sent=0L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'gif0': snetio(bytes_sent=0L, bytes_recv=0L, packets_sent=0L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'lo0': snetio(bytes_sent=869906L, bytes_recv=869906L, packets_sent=3527L, packets_recv=3527L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'p2p0': snetio(bytes_sent=0L, bytes_recv=0L, packets_sent=0L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'stf0': snetio(bytes_sent=0L, bytes_recv=0L, packets_sent=0L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0),

 'utun0': snetio(bytes_sent=268L, bytes_recv=0L, packets_sent=3L, packets_recv=0L, errin=0L, errout=0L, dropin=0L, dropout=0)}


这是一个很有意思的功能,似乎常见的360安全卫视等流量统计工具能够统计到的信息这里都有了。不过,不同的网络节点的单独信息,

不过,获取的信息应该作什么解析现在还没有进行更为详细的学习。暂且先做一个方向性的接触,后期再来一点深入。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值