如何解决如何从Android本地VPN提取所有网络URL
我正在创建运行良好的本地VPN。但是我想获取用户在浏览器中单击的所有网站URL。我也想从数据包中捕获目标地址。
我尝试了互联网上所有可用的方法,但没有找到任何解决方案。
class LocalVpnService : VpnService(){
private enum class Command {
Start
}
companion object {
private const val TAG = "LocalVpnService"
private const val EXTRA_COMMAND = "Command"
@JvmStatic
fun start(context: Context) {
val intent = Intent(context,LocalVpnService::class.java)
intent.putExtra(EXTRA_COMMAND,Command.Start)
context.startService(intent)
}
}
private val closeCh = Channel<Unit>()
private val inputCh = Channel<IpV4Packet>()
private var vpnInterface: ParcelFileDescriptor? = null
private var packet : IpV4Packet ?= null
private var packetV6 : IpV6ExtDestinationOptionsPacket ?= null
override fun onStartCommand(intent: Intent?,flags: Int,startId: Int): Int {
println("QAS onStartCommand: ${intent?.getStringExtra("COMMAND")}")
if (intent?.getStringExtra("COMMAND") == "STOP") {
println("QAS vpn: $vpnInterface")
if(vpnInterface != null){
println("QAS Stop Vpn block")
stopVpn(vpnInterface!!)
}else{
Log.i(TAG,"QAS VPN is not running")
}
}else if(intent?.getStringExtra("COMMAND") == "START"){
Log.i(TAG,"QAS VPN start else if: $vpnInterface")
if(vpnInterface == null){
Log.i(TAG,"QAS VPN is started.")
vpnStart()
}else{
Log.i(TAG,"QAS VPN is already running.")
}
}
return Service.START_STICKY
}
override fun onCreate() {
super.onCreate()
}
override fun onDestroy() {
super.onDestroy()
stopSelf()
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private fun vpnStart(){
// Check if Wi-Fi
val wifi = Util.isWifiActive(this)
Log.i(TAG,"QAS wifi=$wifi")
// Build VPN service
val builder = Builder()
builder.setSession(getString(R.string.app_name))
builder.addAddress("10.1.10.1",24)
builder.addRoute("0.0.0.0",0)
// Add list of allowed applications
for (rule in Rule.getRules(this)) if (!(if (wifi) rule.wifi_blocked else rule.other_blocked)) {
Log.i(TAG,"Allowing " + rule.info.packageName)
try {
builder.addDisallowedApplication(rule.info.packageName)
} catch (e: java.lang.Exception) {
Log.e(TAG,"QAS Exception: $e")
}
}
// Build configure intent
val configure = Intent(this,MainActivity::class.java)
val pi = PendingIntent.getActivity(this,configure,PendingIntent.FLAG_UPDATE_CURRENT)
builder.setConfigureIntent(pi)
vpnInterface = builder.establish()
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。