Monitoring network usage excluding local traffic

前端 未结 8 2055
一整个雨季
一整个雨季 2020-12-29 13:14

I am working on an app that monitors network usage. However I noticed many ways to do this does not allow exclusion of local traffic (say, Time Machine).

I am lookin

8条回答
  •  轮回少年
    2020-12-29 13:46

    The best way is to find the 'external' ip address through the eth0, eth1, or whatever adapter with a system call to ifconfig. Then pull logs for whatever system (messages, syslog, whatever) and write a filter for that external ip address. To make it nicer and more portable, write a regex that will filter for publicly routable IPs only and just filter messages log for that 'external' ip address.

提交回复
热议问题