有没有办法从安卓应用程序中获得Chromebook的真正ip



我有一个Android应用程序,它需要设备的真实IP,而不是虚拟网络IP。我不想要公共IP,除非Chromebook在公共IP上,我只需要局域网的私有IP,但现在我得到了一个虚拟IP,我猜这是一个Android应用程序的虚拟网络。

使用WifiManagerNetworkInterface.getNetworkInterfaces(),我得到的只是虚拟IP。调用外部服务器不起作用,因为那样会获得公共IP。

我知道过去有人问过这个问题,但我只想看看是否有人找到了方法?

ChromeOS.dev.对此有更详细的回答

要获得分配给Chrome操作系统设备连接的最高优先级网络的IPv4地址,请检查android系统属性arc.net.IPv4.host_address,如果需要,还可以检查arc.net.IPv4.host_gateway。一种方法是:

fun getChromeOsIpAddress() : String {
val process = ProcessBuilder().command("/system/bin/getprop", "arc.net.ipv4.host_address").start()
val ipAddress = readInput(process.inputStream)
return ipAddress
}
fun getChromeOsIpGateway() : String {
val process = ProcessBuilder().command("/system/bin/getprop", "arc.net.ipv4.host_gateway").start()
val gatewayAddress = readInput(process.inputStream)
return gatewayAddress
}

这篇文章是在Apache 2.0下授权的。

https://developers.google.com/open-source/devplat

最新更新