- 浏览: 22182475 次
- 性别:
- 来自: 杭州
最新评论
-
ZY199266:
配置文件还需要额外的配置ma
Android 客户端通过内置API(HttpClient) 访问 服务器(用Spring MVC 架构) 返回的json数据全过程 -
ZY199266:
我的一访问为什么是 /mavenwebdemo/WEB-I ...
Android 客户端通过内置API(HttpClient) 访问 服务器(用Spring MVC 架构) 返回的json数据全过程 -
lvgaga:
我又一个问题就是 如果像你的这种形式写。配置文件还需要额外的 ...
Android 客户端通过内置API(HttpClient) 访问 服务器(用Spring MVC 架构) 返回的json数据全过程 -
lvgaga:
我的一访问为什么是 /mavenwebdemo/WEB-I ...
Android 客户端通过内置API(HttpClient) 访问 服务器(用Spring MVC 架构) 返回的json数据全过程 -
y1210251848:
你的那个错误应该是项目所使用的目标框架不支持吧
log4net配置(web中使用log4net,把web.config放在单独的文件中)
Android防火墙+流量统计代码
首届 Google 暑期大学生博客分享大赛——2010 Andriod 篇
BroadcastReceiver模块
用于监听开机信息 并初始化和启动服务
view plaincopy to clipboardprint?
package zy.dnh;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class getpowerinfo extends BroadcastReceiver{
FileOutputStream out;
final public String ONPATH = "/data/data/zy.dnh/on.txt";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent bootActivityIntent=new Intent(context,mService1.class);//启动服务
bootActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
writefile("0,0,0,0,0,0,0,0,0,0,0,0",ONPATH);
context.startService(bootActivityIntent);
Toast.makeText(context, "Netcounter service has been lauched", Toast.LENGTH_LONG).show();
Api.applySavedIptablesRules(context, false);//应用防火墙规则
Toast.makeText(context, "Wall rules have been lauched", Toast.LENGTH_LONG).show();
}
}
public void writefile(String str,String path )
{
File file;
try {
//创建文件
file = new File(path);
file.createNewFile();
//打开文件file的OutputStream
out = new FileOutputStream(file);
String infoToWrite = str;
//将字符串转换成byte数组写入文件
out.write(infoToWrite.getBytes());
//关闭文件file的OutputStream
out.close();
} catch (IOException e) {
//将出错信息打印到Logcat
}
package zy.dnh;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class getpowerinfo extends BroadcastReceiver{
FileOutputStream out;
final public String ONPATH = "/data/data/zy.dnh/on.txt";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent bootActivityIntent=new Intent(context,mService1.class);//启动服务
bootActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
writefile("0,0,0,0,0,0,0,0,0,0,0,0",ONPATH);
context.startService(bootActivityIntent);
Toast.makeText(context, "Netcounter service has been lauched", Toast.LENGTH_LONG).show();
Api.applySavedIptablesRules(context, false);//应用防火墙规则
Toast.makeText(context, "Wall rules have been lauched", Toast.LENGTH_LONG).show();
}
}
public void writefile(String str,String path )
{
File file;
try {
//创建文件
file = new File(path);
file.createNewFile();
//打开文件file的OutputStream
out = new FileOutputStream(file);
String infoToWrite = str;
//将字符串转换成byte数组写入文件
out.write(infoToWrite.getBytes());
//关闭文件file的OutputStream
out.close();
} catch (IOException e) {
//将出错信息打印到Logcat
}
mService1模块
后台服务,用于维护流量日志
view plaincopy to clipboardprint?
public class mService1 extends Service
{
private Handler objHandler = new Handler();
private int intCounter=0;
private int mHour;
private int mMinute;
private int mYear;
private int mMonth;
private int mDay;
private String mdate;
final public String DEV_FILE = "/proc/self/net/dev";//系统流量文件
String[] ethdata={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
String[] gprsdata={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
String[] wifidata={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
String data="0,0,0,0,0,0,0,0,0,0,0,0";//对应on.txt里面的格式
final String ETHLINE=" eth0";//以太网信息所在行
final String GPRSLINE="rmnet0";
final String WIFILINE="tiwlan0";
final String TEXT_ENCODING = "UTF-8";
final public String ONPATH = "/data/data/zy.dnh/on.txt";
final public String LOGPATH = "/data/data/zy.dnh/log.txt";
private Runnable mTasks = new Runnable()
{
public void run()//运行该服务执行此函数
{
refresh();
intCounter++;
// DisplayToast("Counter:"+Integer.toString(intCounter));
objHandler.postDelayed(mTasks, 30000);//每3000毫秒执行一次
}
};
@Override
public void onStart(Intent intent, int startId)
{
// TODO Auto-generated method stub
//writefile("0,0,0,0,0,0,0,0,0,0,0,0",ONPATH);//每次启动服务 初始化onpath
objHandler.postDelayed(mTasks, 0);
super.onStart(intent, startId);
}
@Override
public void onCreate()
{
// TODO Auto-generated method stub
super.onCreate();
}
@Override
public IBinder onBind(Intent intent)
{
// TODO Auto-generated method stub
return null;
}
@Override
public void onDestroy()
{
// TODO Auto-generated method stub
/* */
objHandler.removeCallbacks(mTasks);
super.onDestroy();
}
public void DisplayToast(String str)
{
Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
}
public void readdev()
{
FileReader fstream = null;
try {
fstream = new FileReader(DEV_FILE);
}
catch (FileNotFoundException e) {
DisplayToast("Could not read " + DEV_FILE);
}
BufferedReader in = new BufferedReader(fstream, 500);
String line;
String[] segs;
String[] netdata;
int count=0;
int k;
int j;
try {
while ((line = in.readLine()) != null) {
segs = line.trim().split(":");
if(line.startsWith(ETHLINE))
{
netdata=segs[1].trim().split(" ");
for(k=0,j=0;k<netdata.length;k++)
{
if(netdata[k].length()>0)
{
ethdata[j]=netdata[k];
j++;
}
}
}
else if(line.startsWith(GPRSLINE))
{
netdata=segs[1].trim().split(" ");
for(k=0,j=0;k<netdata.length;k++)
{
if(netdata[k].length()>0)
{
gprsdata[j]=netdata[k];
j++;
}
}
}
else if(line.startsWith(WIFILINE))
{
netdata=segs[1].trim().split(" ");
for(k=0,j=0;k<netdata.length;k++)
{
if(netdata[k].length()>0)
{
wifidata[j]=netdata[k];
j++;
}
}
}
count++;
}
fstream.close();
}
catch (IOException e) {
DisplayToast(e.toString());
}
}
public String getinfo(String path)
{
File file;
String str="";
FileInputStream in;
try{
//打开文件file的InputStream
file = new File(path);
in = new FileInputStream(file);
//将文件内容全部读入到byte数组
int length = (int)file.length();
byte[] temp = new byte[length];
in.read(temp, 0, length);
//将byte数组用UTF-8编码并存入display字符串中
str = EncodingUtils.getString(temp,TEXT_ENCODING);
//关闭文件file的InputStream
in.close();
}
catch (IOException e) {
DisplayToast(e.toString());
}
return str;
}
public void writefile(String str,String path )
{
File file;
FileOutputStream out;
try {
//创建文件
file = new File(path);
file.createNewFile();
//打开文件file的OutputStream
out = new FileOutputStream(file);
String infoToWrite = str;
//将字符串转换成byte数组写入文件
out.write(infoToWrite.getBytes());
//关闭文件file的OutputStream
out.close();
} catch (IOException e) {
//将出错信息打印到Logcat
DisplayToast(e.toString());
}
}
public void refresh()
{
readdev();//读取本次开机之后直到当前系统的总流量
data=ethdata[0]+","+ethdata[1]+","+ethdata[8]+","+ethdata[9]+","
+gprsdata[0]+","+gprsdata[1]+","+gprsdata[8]+","+gprsdata[9]+","
+wifidata[0]+","+wifidata[1]+","+wifidata[8]+","+wifidata[9];
String onstr=getinfo(ONPATH);//读取on.txt记录到onstr里
String ondata[]=onstr.split(",");//将onstr各项分离 放到ondata里
//计算增量
int [] delta=new int [12];
delta[0]=Integer.parseInt(ethdata[0])-Integer.parseInt(ondata[0]);
delta[1]=Integer.parseInt(ethdata[1])-Integer.parseInt(ondata[1]);
delta[2]=Integer.parseInt(ethdata[8])-Integer.parseInt(ondata[2]);
delta[3]=Integer.parseInt(ethdata[9])-Integer.parseInt(ondata[3]);
delta[4]=Integer.parseInt(gprsdata[0])-Integer.parseInt(ondata[4]);
delta[5]=Integer.parseInt(gprsdata[1])-Integer.parseInt(ondata[5]);
delta[6]=Integer.parseInt(gprsdata[8])-Integer.parseInt(ondata[6]);
delta[7]=Integer.parseInt(gprsdata[9])-Integer.parseInt(ondata[7]);
delta[8]=Integer.parseInt(wifidata[0])-Integer.parseInt(ondata[8]);
delta[9]=Integer.parseInt(wifidata[1])-Integer.parseInt(ondata[9]);
delta[10]=Integer.parseInt(wifidata[8])-Integer.parseInt(ondata[10]);
delta[11]=Integer.parseInt(wifidata[9])-Integer.parseInt(ondata[11]);
//读取log.txt
//获取当前时间
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR); //获取当前年份
mMonth = c.get(Calendar.MONTH)+1;//获取当前月份
mDay = c.get(Calendar.DAY_OF_MONTH);//获取当前月份的日期号码
mHour = c.get(Calendar.HOUR_OF_DAY);//获取当前的小时数
mMinute = c.get(Calendar.MINUTE);//获取当前的分钟数
mdate=mYear+"-"+mMonth+"-"+mDay;
String text=getinfo(LOGPATH);//将log.txt的内容读到text字符串中
String [] line=text.split("/n");
String today=line[line.length-1];//获得今日已记录流量
String [] beToday=today.split(",");
//检查文件最后一行是否为今天的流量记录信息
if(!beToday[0].equals(mdate))//
//判断今日流量是否已经记录,如果今日流量没有记录
{
text=text+mdate+",0,0,0,0,0,0,0,0,0,0,0,0/n";
writefile(text,LOGPATH);
line=text.split("/n");
today=line[line.length-1];//获得今日已记录流量
beToday=today.split(",");
}
int i;
//处理今日流量
int [] newTodaydata=new int [12];//表示今日流量
String newtoday=mdate;
for(i=0;i<=11;i++)//更新今日流量
{
newTodaydata[i]=Integer.parseInt(beToday[i+1])+delta[i];
newtoday=newtoday+","+newTodaydata[i];
}
newtoday=newtoday+"/n";
String [] beTotal=line[0].split(",");
int [] newTotaldata=new int [12];//表示总流量数值
//更新第一行
String newtotal="total";
for(i=0;i<=11;i++)//更新今日流量和总流量
{
newTotaldata[i]=Integer.parseInt(beTotal[i+1])+delta[i];//总流量数值+delta[i]更新
newtotal=newtotal+","+newTotaldata[i];
}
newtotal= newtotal+"/n";
//处理中间不变的部分
String before="";//before为之前的从第1行到昨天的流量记录
for(i=1;i<=line.length-2;i++)
before=before+line[i]+"/n";//代表中间不变的部分
String newlog=newtotal+before+newtoday;
writefile(data,ONPATH);//更新流量记录
writefile(newlog,LOGPATH);//更新log*/
}
}
public class mService1 extends Service
{
private Handler objHandler = new Handler();
private int intCounter=0;
private int mHour;
private int mMinute;
private int mYear;
private int mMonth;
private int mDay;
private String mdate;
final public String DEV_FILE = "/proc/self/net/dev";//系统流量文件
String[] ethdata={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
String[] gprsdata={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
String[] wifidata={"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"};
String data="0,0,0,0,0,0,0,0,0,0,0,0";//对应on.txt里面的格式
final String ETHLINE=" eth0";//以太网信息所在行
final String GPRSLINE="rmnet0";
final String WIFILINE="tiwlan0";
final String TEXT_ENCODING = "UTF-8";
final public String ONPATH = "/data/data/zy.dnh/on.txt";
final public String LOGPATH = "/data/data/zy.dnh/log.txt";
private Runnable mTasks = new Runnable()
{
public void run()//运行该服务执行此函数
{
refresh();
intCounter++;
// DisplayToast("Counter:"+Integer.toString(intCounter));
objHandler.postDelayed(mTasks, 30000);//每3000毫秒执行一次
}
};
@Override
public void onStart(Intent intent, int startId)
{
// TODO Auto-generated method stub
//writefile("0,0,0,0,0,0,0,0,0,0,0,0",ONPATH);//每次启动服务 初始化onpath
objHandler.postDelayed(mTasks, 0);
super.onStart(intent, startId);
}
@Override
public void onCreate()
{
// TODO Auto-generated method stub
super.onCreate();
}
@Override
public IBinder onBind(Intent intent)
{
// TODO Auto-generated method stub
return null;
}
@Override
public void onDestroy()
{
// TODO Auto-generated method stub
/* */
objHandler.removeCallbacks(mTasks);
super.onDestroy();
}
public void DisplayToast(String str)
{
Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
}
public void readdev()
{
FileReader fstream = null;
try {
fstream = new FileReader(DEV_FILE);
}
catch (FileNotFoundException e) {
DisplayToast("Could not read " + DEV_FILE);
}
BufferedReader in = new BufferedReader(fstream, 500);
String line;
String[] segs;
String[] netdata;
int count=0;
int k;
int j;
try {
while ((line = in.readLine()) != null) {
segs = line.trim().split(":");
if(line.startsWith(ETHLINE))
{
netdata=segs[1].trim().split(" ");
for(k=0,j=0;k<netdata.length;k++)
{
if(netdata[k].length()>0)
{
ethdata[j]=netdata[k];
j++;
}
}
}
else if(line.startsWith(GPRSLINE))
{
netdata=segs[1].trim().split(" ");
for(k=0,j=0;k<netdata.length;k++)
{
if(netdata[k].length()>0)
{
gprsdata[j]=netdata[k];
j++;
}
}
}
else if(line.startsWith(WIFILINE))
{
netdata=segs[1].trim().split(" ");
for(k=0,j=0;k<netdata.length;k++)
{
if(netdata[k].length()>0)
{
wifidata[j]=netdata[k];
j++;
}
}
}
count++;
}
fstream.close();
}
catch (IOException e) {
DisplayToast(e.toString());
}
}
public String getinfo(String path)
{
File file;
String str="";
FileInputStream in;
try{
//打开文件file的InputStream
file = new File(path);
in = new FileInputStream(file);
//将文件内容全部读入到byte数组
int length = (int)file.length();
byte[] temp = new byte[length];
in.read(temp, 0, length);
//将byte数组用UTF-8编码并存入display字符串中
str = EncodingUtils.getString(temp,TEXT_ENCODING);
//关闭文件file的InputStream
in.close();
}
catch (IOException e) {
DisplayToast(e.toString());
}
return str;
}
public void writefile(String str,String path )
{
File file;
FileOutputStream out;
try {
//创建文件
file = new File(path);
file.createNewFile();
//打开文件file的OutputStream
out = new FileOutputStream(file);
String infoToWrite = str;
//将字符串转换成byte数组写入文件
out.write(infoToWrite.getBytes());
//关闭文件file的OutputStream
out.close();
} catch (IOException e) {
//将出错信息打印到Logcat
DisplayToast(e.toString());
}
}
public void refresh()
{
readdev();//读取本次开机之后直到当前系统的总流量
data=ethdata[0]+","+ethdata[1]+","+ethdata[8]+","+ethdata[9]+","
+gprsdata[0]+","+gprsdata[1]+","+gprsdata[8]+","+gprsdata[9]+","
+wifidata[0]+","+wifidata[1]+","+wifidata[8]+","+wifidata[9];
String onstr=getinfo(ONPATH);//读取on.txt记录到onstr里
String ondata[]=onstr.split(",");//将onstr各项分离 放到ondata里
//计算增量
int [] delta=new int [12];
delta[0]=Integer.parseInt(ethdata[0])-Integer.parseInt(ondata[0]);
delta[1]=Integer.parseInt(ethdata[1])-Integer.parseInt(ondata[1]);
delta[2]=Integer.parseInt(ethdata[8])-Integer.parseInt(ondata[2]);
delta[3]=Integer.parseInt(ethdata[9])-Integer.parseInt(ondata[3]);
delta[4]=Integer.parseInt(gprsdata[0])-Integer.parseInt(ondata[4]);
delta[5]=Integer.parseInt(gprsdata[1])-Integer.parseInt(ondata[5]);
delta[6]=Integer.parseInt(gprsdata[8])-Integer.parseInt(ondata[6]);
delta[7]=Integer.parseInt(gprsdata[9])-Integer.parseInt(ondata[7]);
delta[8]=Integer.parseInt(wifidata[0])-Integer.parseInt(ondata[8]);
delta[9]=Integer.parseInt(wifidata[1])-Integer.parseInt(ondata[9]);
delta[10]=Integer.parseInt(wifidata[8])-Integer.parseInt(ondata[10]);
delta[11]=Integer.parseInt(wifidata[9])-Integer.parseInt(ondata[11]);
//读取log.txt
//获取当前时间
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR); //获取当前年份
mMonth = c.get(Calendar.MONTH)+1;//获取当前月份
mDay = c.get(Calendar.DAY_OF_MONTH);//获取当前月份的日期号码
mHour = c.get(Calendar.HOUR_OF_DAY);//获取当前的小时数
mMinute = c.get(Calendar.MINUTE);//获取当前的分钟数
mdate=mYear+"-"+mMonth+"-"+mDay;
String text=getinfo(LOGPATH);//将log.txt的内容读到text字符串中
String [] line=text.split("/n");
String today=line[line.length-1];//获得今日已记录流量
String [] beToday=today.split(",");
//检查文件最后一行是否为今天的流量记录信息
if(!beToday[0].equals(mdate))//
//判断今日流量是否已经记录,如果今日流量没有记录
{
text=text+mdate+",0,0,0,0,0,0,0,0,0,0,0,0/n";
writefile(text,LOGPATH);
line=text.split("/n");
today=line[line.length-1];//获得今日已记录流量
beToday=today.split(",");
}
int i;
//处理今日流量
int [] newTodaydata=new int [12];//表示今日流量
String newtoday=mdate;
for(i=0;i<=11;i++)//更新今日流量
{
newTodaydata[i]=Integer.parseInt(beToday[i+1])+delta[i];
newtoday=newtoday+","+newTodaydata[i];
}
newtoday=newtoday+"/n";
String [] beTotal=line[0].split(",");
int [] newTotaldata=new int [12];//表示总流量数值
//更新第一行
String newtotal="total";
for(i=0;i<=11;i++)//更新今日流量和总流量
{
newTotaldata[i]=Integer.parseInt(beTotal[i+1])+delta[i];//总流量数值+delta[i]更新
newtotal=newtotal+","+newTotaldata[i];
}
newtotal= newtotal+"/n";
//处理中间不变的部分
String before="";//before为之前的从第1行到昨天的流量记录
for(i=1;i<=line.length-2;i++)
before=before+line[i]+"/n";//代表中间不变的部分
String newlog=newtotal+before+newtoday;
writefile(data,ONPATH);//更新流量记录
writefile(newlog,LOGPATH);//更新log*/
}
}
应用iptable规则模块,通过运行iptable脚本来实现iptable规则的应用
view plaincopy to clipboardprint?
private static boolean applyIptablesRulesImpl(Context ctx, List<Integer> uids, boolean showErrors) {
if (ctx == null) {
return false;
}
final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, 0);
final boolean whitelist = prefs.getString(PREF_MODE, MODE_WHITELIST).equals(MODE_WHITELIST);
boolean wifi = false; // Wi-fi selected ?
final String itfs = prefs.getString(PREF_ITFS, ITF_3G);
String itfFilter;
if (itfs.indexOf("|") != -1) {
itfFilter = ""; // Block all interfaces
wifi = true;
} else if (itfs.indexOf(ITF_3G) != -1) {
itfFilter = "-o rmnet+";;
// Block all rmnet interfaces
} else {
itfFilter = "-o tiwlan+";;
// Block all tiwlan interfaces
wifi = true;
}
final StringBuilder script = new StringBuilder();
try {
int code;
script.append("iptables -F || exit/n");
final String targetRule = (whitelist ? "ACCEPT" : "REJECT");
if (whitelist && wifi) {
// When "white listing" Wi-fi, we need ensure that the dhcp and wifi users are allowed
int uid = android.os.Process.getUidForName("dhcp");
if (uid != -1) script.append("iptables -A OUTPUT "
+ itfFilter + " -m owner --uid-owner " + uid + " -j ACCEPT || exit/n");
uid = android.os.Process.getUidForName("wifi");
if (uid != -1) script.append("iptables -A OUTPUT " + itfFilter + " -m owner --uid-owner " + uid + " -j ACCEPT || exit/n"); }
for (Integer uid : uids) {
script.append("iptables -A OUTPUT " + itfFilter
+ " -m owner --uid-owner " + uid + " -j " + targetRule + " || exit/n");
}
if (whitelist) {
script.append("iptables -A OUTPUT " + itfFilter + " -j REJECT || exit/n");
}
StringBuilder res = new StringBuilder();
code = runScriptAsRoot(script.toString(), res);
if (showErrors && code != 0) {
String msg = res.toString();
Log.e("DroidWall", msg);
// Search for common error messages
if (msg.indexOf("Couldn't find match `owner'") != -1 || msg.indexOf("no chain/target match") != -1) {
alert(ctx, "Error applying iptables rules./nExit code: " + code + "/n/n" +"It seems your Linux kernel was not compiled with the netfilter /"owner/" module enabled, which is required for Droid Wall to work properly./n/n" +"You should check if there is an updated version of your Android ROM compiled with this kernel module.");
} else {
// Remove unnecessary help message from output
if (msg.indexOf("/nTry `iptables -h' or 'iptables --help' for more information.") != -1) {
msg = msg.replace("/nTry `iptables -h' or 'iptables --help' for more information.", "");
}
// Try `iptables -h' or 'iptables --help' for more information.
alert(ctx, "Error applying iptables rules. Exit code: " + code + "/n/n" + msg.trim());
}
} else {
return true;
}
} catch (Exception e) {
if (showErrors) alert(ctx, "error refreshing iptables: " + e);
}
return false;
}
private static boolean applyIptablesRulesImpl(Context ctx, List<Integer> uids, boolean showErrors) {
if (ctx == null) {
return false;
}
final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, 0);
final boolean whitelist = prefs.getString(PREF_MODE, MODE_WHITELIST).equals(MODE_WHITELIST);
boolean wifi = false; // Wi-fi selected ?
final String itfs = prefs.getString(PREF_ITFS, ITF_3G);
String itfFilter;
if (itfs.indexOf("|") != -1) {
itfFilter = ""; // Block all interfaces
wifi = true;
} else if (itfs.indexOf(ITF_3G) != -1) {
itfFilter = "-o rmnet+";;
// Block all rmnet interfaces
} else {
itfFilter = "-o tiwlan+";;
// Block all tiwlan interfaces
wifi = true;
}
final StringBuilder script = new StringBuilder();
try {
int code;
script.append("iptables -F || exit/n");
final String targetRule = (whitelist ? "ACCEPT" : "REJECT");
if (whitelist && wifi) {
// When "white listing" Wi-fi, we need ensure that the dhcp and wifi users are allowed
int uid = android.os.Process.getUidForName("dhcp");
if (uid != -1) script.append("iptables -A OUTPUT "
+ itfFilter + " -m owner --uid-owner " + uid + " -j ACCEPT || exit/n");
uid = android.os.Process.getUidForName("wifi");
if (uid != -1) script.append("iptables -A OUTPUT " + itfFilter + " -m owner --uid-owner " + uid + " -j ACCEPT || exit/n"); }
for (Integer uid : uids) {
script.append("iptables -A OUTPUT " + itfFilter
+ " -m owner --uid-owner " + uid + " -j " + targetRule + " || exit/n");
}
if (whitelist) {
script.append("iptables -A OUTPUT " + itfFilter + " -j REJECT || exit/n");
}
StringBuilder res = new StringBuilder();
code = runScriptAsRoot(script.toString(), res);
if (showErrors && code != 0) {
String msg = res.toString();
Log.e("DroidWall", msg);
// Search for common error messages
if (msg.indexOf("Couldn't find match `owner'") != -1 || msg.indexOf("no chain/target match") != -1) {
alert(ctx, "Error applying iptables rules./nExit code: " + code + "/n/n" +"It seems your Linux kernel was not compiled with the netfilter /"owner/" module enabled, which is required for Droid Wall to work properly./n/n" +"You should check if there is an updated version of your Android ROM compiled with this kernel module.");
} else {
// Remove unnecessary help message from output
if (msg.indexOf("/nTry `iptables -h' or 'iptables --help' for more information.") != -1) {
msg = msg.replace("/nTry `iptables -h' or 'iptables --help' for more information.", "");
}
// Try `iptables -h' or 'iptables --help' for more information.
alert(ctx, "Error applying iptables rules. Exit code: " + code + "/n/n" + msg.trim());
}
} else {
return true;
}
} catch (Exception e) {
if (showErrors) alert(ctx, "error refreshing iptables: " + e);
}
return false;
}
本文来自CSDN博客,出处:http://blog.csdn.net/Zengyangtech/archive/2010/06/01/5638604.aspx
相关推荐
网络防火墙有流量预警功能,可以设置2G3G和wifi的数据流量和显示流量统计。小工具有android的命令行工具,测试了一下可以使用一些简单的liunx命令。还有一个超级终端功能。任务管理器可以结束进程和查看进程的通话...
2. **内存清理**:这部分代码可能会展示如何监控并释放Android系统的内存,提高设备运行速度。它可能涉及到系统进程的管理,以及优化内存分配策略。 3. **垃圾清理**:源码可能包含如何扫描和删除无用的缓存文件、...
NGFW不仅仅是传统的防火墙,它提供了更高级别的安全防护,能够基于应用层进行策略控制,阻止恶意流量进入或离开Android设备。通过配置合适的NGFW规则,可以有效防止恶意软件的传播和数据泄露。 “安全研究”是持续...
6. **数据分析**:提供销售报表、流量统计等数据报告,帮助商家了解运营情况并做出决策。 #### 部署与配置 1. **环境搭建**:部署HiMaill3.0前需要搭建好相应的运行环境,包括安装.NET Framework、配置Web服务器...
5. **网络流量监控**:实施流量管理、统计和权限控制,以便及时发现异常行为。 此外,文档还可能涵盖了网络外联控制,如使用IPsec协议提供加密认证,建立安全的数据传输通道,以及使用如OPENSSL这样的安全数据传输...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
- **首个版本**: 1994年3月发布了Linux 1.0,包含17万行代码。 - **许可证**: 采用了GPL许可协议,确保了Linux的开源性和可自由修改性。 - **优点**: - 稳定性高: 长时间运行无需重启。 - 成本低: 许多版本是...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...
Port Groper可以与用测试防火墙,干扰web 统计脚本的跟踪,为网站增加流量..往好了用什么都能干,就是不能让一个网站下线。 FTP客户端Java类库 ftp4j ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分...