Skip to content

Instantly share code, notes, and snippets.

@supercurio
Created October 24, 2017 23:19
Show Gist options
  • Save supercurio/cb5eadb1862edb99b158d6ad533b3037 to your computer and use it in GitHub Desktop.
Save supercurio/cb5eadb1862edb99b158d6ad533b3037 to your computer and use it in GitHub Desktop.
private fun getAllWifiSubnetIpAddresses(): List<InetAddress> {
val wifiMgr = getSystemService(WIFI_SERVICE) as WifiManager
val wlanAddr = NetworkUtils.intToInetAddress(wifiMgr.dhcpInfo.ipAddress)
return NetworkInterface.getNetworkInterfaces().toList()
.flatMap { it.interfaceAddresses }
.filter { it.address == wlanAddr }
.map { SubnetUtils(it.address.hostAddress + "/" + it.networkPrefixLength) }
.flatMap { it.info.allAddresses.asList() }
.map { Inet4Address.getByName(it) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment