如何监控Android上的传入和传出IP流量

时间:2013-11-20 11:04:22

标签: android linux networking proc

我必须为android编写一个网络监控应用程序,其中一个必要条件是监控所有传入和传出的IP流量,我发现/ proc / stat / netstat文件,我很确定包含我想要的内容,问题是:我找不到任何地方如何阅读它。 谁知道/ proc / stat / netstat的内部格式?我必须监视系统正在生成的IP流量,我在该文件中找到了一个名为“IpExt”的条目,后面有一些数字,但是我无法弄明白......有人知道吗?

由于

1 个答案:

答案 0 :(得分:0)

linux内核中的net / ipv4 / proc.c文件可以做到这一点。

/* Following items are displayed in /proc/net/netstat */
static const struct snmp_mib snmp4_ipextstats_list[] = {
        SNMP_MIB_ITEM("InNoRoutes", IPSTATS_MIB_INNOROUTES),
        SNMP_MIB_ITEM("InTruncatedPkts", IPSTATS_MIB_INTRUNCATEDPKTS),
        SNMP_MIB_ITEM("InMcastPkts", IPSTATS_MIB_INMCASTPKTS),
        SNMP_MIB_ITEM("OutMcastPkts", IPSTATS_MIB_OUTMCASTPKTS),
        SNMP_MIB_ITEM("InBcastPkts", IPSTATS_MIB_INBCASTPKTS),
        SNMP_MIB_ITEM("OutBcastPkts", IPSTATS_MIB_OUTBCASTPKTS),
        SNMP_MIB_ITEM("InOctets", IPSTATS_MIB_INOCTETS),
        SNMP_MIB_ITEM("OutOctets", IPSTATS_MIB_OUTOCTETS),
        SNMP_MIB_ITEM("InMcastOctets", IPSTATS_MIB_INMCASTOCTETS),
        SNMP_MIB_ITEM("OutMcastOctets", IPSTATS_MIB_OUTMCASTOCTETS),
        SNMP_MIB_ITEM("InBcastOctets", IPSTATS_MIB_INBCASTOCTETS),
        SNMP_MIB_ITEM("OutBcastOctets", IPSTATS_MIB_OUTBCASTOCTETS),
        /* Non RFC4293 fields */
        SNMP_MIB_ITEM("InCsumErrors", IPSTATS_MIB_CSUMERRORS),
        SNMP_MIB_ITEM("InNoECTPkts", IPSTATS_MIB_NOECTPKTS),
        SNMP_MIB_ITEM("InECT1Pkts", IPSTATS_MIB_ECT1PKTS),
        SNMP_MIB_ITEM("InECT0Pkts", IPSTATS_MIB_ECT0PKTS),
        SNMP_MIB_ITEM("InCEPkts", IPSTATS_MIB_CEPKTS),
        SNMP_MIB_SENTINEL
};