实现思路: 通过iptables命令设置filter表,针对OUTPUT链,来源是wifi或是移动数据(4g/3g/…)的做REJECT或是DROP操作。 REJECT 拦阻该封包,并传送封包通知对方。 DROP 丢弃封包不予处理,进行完此处理动作后,将不再比对其它规则,直接中断过滤程序。 REJECT和DROP其效果都可以使app无法联网,所以两个任你选择使用。
封包来源: wifi: tiwlan+, wlan+, eth+ 移动网络:rmnet+,pdp+,ppp+,uwbr+,wimax+,vsnet+
Android网络防火墙开源实现:droidwall
参考: Iptables实现限制网络访问功能探讨 http://blog.sina.com.cn/s/blog_9676eefb010154tr.html (一)洞悉linux下的Netfilter&iptables:什么是Netfilter? http://blog.chinaunix.net/uid-23069658-id-3160506.html Android下基于Iptables的一种app网络访问控制方案(一) http://www.th7.cn/Program/Android/201512/711155.shtml droidwall源码实现分析 http://taoyuanxiaoqi.com/2015/02/05/droidwallstudy/?utm_source=tuicool&utm_medium=referral Droidwall原理简析 http://blog.csdn.net/earbao/article/details/8727425 Android 开源项目Droidwall初探记录 http://www.fx114.net/qa-101-130267.aspx