如下所示,在BASH中使用 grep bytes | awk '{print $2}'| awk -F":" '{print $2}') 就可以抓出RX bytes:719757611,同样在python中如何抓取呢
eth0 Link encap:Ethernet HWaddr 6C:F0:49:A2:08:07
inet addr:192.168.1.216 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::6ef0:49ff:fea2:807/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6421518 errors:0 dropped:0 overruns:0 frame:0
TX packets:57581 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
[fly] RX bytes:719757611 (686.4 MiB) TX bytes:7515290 (7.1 MiB)[/fly]
Interrupt:233 Base address:0xc000
#-*- coding: utf-8 -*-
#!/usr/bin/python
import os,re
p=re.compile("RX bytes:\d+")
for i in os.popen('ifconfig'):
m=p.findall(i.strip())
if m:
print m[0]
阅读(1211) | 评论(0) | 转发(0) |