我现在一直在寻找我的答案几个小时,我无法弄明白.请帮忙.
我想要做的是使用Android中的VpnService来获取网络数据包,如应用程序tPacketCapture
我开始使用谷歌的ToyVpn示例代码并对其进行修改,因此我不会将数据发送到服务器.但是,我不确定这是否正确.
我的configure方法在调用establish()之前使用binder.addAddress()的wlan ip地址.我正在使用nexus 7并使用"adb shell netcfg | grep wlan0"来获取地址:
wlan0 UP 192.168.0.6/24 0x00001043 10:bf:48:bf:5f:9d
并在我的方法中添加它:
private void configure() throws Exception {
// If the old interface has exactly the same parameters, use it!
if (mInterface != null) {
Log.i(TAG, "Using the previous interface");
return;
}
// Configure a builder while parsing the parameters.
Builder builder = new Builder();
builder.setMtu(1500);
builder.addAddress("192.168.0.6", 24);
try {
mInterface.close();
} catch (Exception e) {
// ignore
}
mInterface = builder.establish();
}
Run Code Online (Sandbox Code Playgroud)
在调用之后,我调用我修改的run方法来传递String而不是InetSocketAddress,这并不重要,因为我没有在任何地方使用它: …
我正在尝试使用VpnService为BS项目实现一个简单的Android防火墙.我选择VpnService是因为它将在非root设备上运行.它将记录连接并让您过滤连接.(基于IP)
有一个应用程序这样做是有可能的.
我做了一些研究,发现VpnService创建了一个Tun接口.而已.(没有VPN实现只是一个隧道)它允许您为此接口添加地址并添加路由.它返回一个文件描述符.您可以读取传出的包并写入传入的包.
我创建了一个VpnService派生类,我开始服务.我可以tun0使用VpnService.Builder类进行配置.当我查看mobiwol's与adb shell netcfg它的连接时,创建一个tun010.2.3.4/32地址的接口.它将所有程序包路由到此专用网络并发送到Internet.我也在尝试.创建了10.0.0.2/32地址的接口.添加了具有addRoute功能的路由.0.0.0.0/0所以据我所知,我可以从所有网络捕获所有包.(我对这个主题很新,还在学习.我在互联网上找到了作品,所以我不太确定.如果我错了,请纠正我.)
我在服务中创建了2个线程.一个从文件描述符读取并使用受保护的套接字将其写入127.0.0.1.(我不确定我是否应该读/写127.0.0.1.也许这就是问题所在.)
我分析了从文件描述符中读取的数据包.例如:
01000101 byte:69 //ipv4 20byte header
00000000 byte:0 //TOS
00000000 byte:0 //Total Length
00111100 byte:60 //Total Length
11111100 byte:-4 //ID
11011011 byte:-37 //ID
01000000 byte:64 //fragment
00000000 byte:0 //"
01000000 byte:64 //TTL
00000110 byte:6 //Protocol 6 -> TCP
01011110 byte:94 //Header checksum
11001111 byte:-49 //Header checksum
00001010 byte:10 //10.0.0.2
00000000 byte:0
00000000 byte:0
00000010 byte:2
10101101 byte:-83 //173.194.39.78 //google
00111110 byte:-62
00100111 byte:39 …Run Code Online (Sandbox Code Playgroud)