Android 开源项目Droidwall初探记录本来有个类似防火墙的功能需要实现,就花了点时间参考了下Droidwall。360
Android 开源项目Droidwall初探记录
本来有个类似防火墙的功能需要实现,就花了点时间参考了下Droidwall。360的流量控制也是内嵌了Droidwall,有想做这方面的可以研究下这个的源代码。
?
它在v1.5.3? 版本中增加了 Added support for custom scripts. See CustomScripts for more details,可以添加一些iptables规则,达到屏蔽网站地址的效果。
?
?
项目地址:https://code.google.com/p/droidwall/
源代码下载地址:http://droidwall.googlecode.com/svn/
?
此应用需要有root权限的手机,我安装的版本v1.5.6 效果图
?
?
关于CustomScripts 具体的使用方法,翻译的不是很准确,用的google翻译,看懂意思就行。
?
尝试运用我的自订规则,但报告任何失败(中止)
# Try to apply my custom rule, but report any failure (and abort)
$IPTABLES -A droidwall --destination 192.168.0.1 -j RETURN || exit
尝试申请另一个自定义的规则,但忽略任何错误
# Try to apply another custom rule, but ignore any errors on it
$IPTABLES -A droidwall -p TCP --destination-port 80 -j droidwall-reject
Loading scripts from files
Big scripts can be quite hard to edit in the "Set custom script" screen, so it may be a good idea to put your script in a file, then load it from there.
To do that, just use the "." (dot) shell command in the "Set custom script" dialog to load your script from an external file. E.g.:
. /path/to/script.sh
This will cause your script file to be loaded and executed every time the rules are applied.
You can even have multiple scripts executed in sequence...
. /path/to/load-modules.sh
. /path/to/myrules.sh
. /path/to/myscript.sh
However, please note that this can create a serious security breach on your device, since the script will be always executed as root! You must place your script where other applications will not be able to modify it (the sdcard is NOT a good place).
大脚本编辑在“设置自定义脚本”屏幕是十分困难的,因此它可能是一个好主意,把你的脚本文件,然后从那里加载。
要做到这一点,只需使用“.” (点)在“设置自定义脚本”对话框,从外部文件加载脚本的shell命令。例如:
. /path/to/script.sh
这将导致您的脚本文件被加载并执行每一个规则的应用。
你甚至可以有多个顺序执行脚本....
. /path/to/load-modules.sh
. /path/to/myrules.sh
. /path/to/myscript.sh
?
?
?
?
?