Implement MAC lookup (#68)

* Implement MAC lookup

* Refine error processing

* Use long to store MAC consistently

* Link back to macvendors.co

* Undo some havoc

* Do not show mac spans for TV

* Show MAC and IP in a consistent order

* Add IP spans by ipinfo.io

* Add SpanFormatter

* Fix IPv6 ipinfo.io link

* Refine SpanFormatter

* Fix pressing the link
This commit is contained in:
Mygod
2019-01-26 21:20:40 +08:00
committed by GitHub
parent 94114f7a4b
commit d4208affbb
38 changed files with 562 additions and 112 deletions

View File

@@ -1,5 +1,6 @@
package be.mygod.vpnhotspot.net
import be.mygod.vpnhotspot.room.macToLong
import be.mygod.vpnhotspot.util.parseNumericAddress
import timber.log.Timber
import java.io.File
@@ -8,7 +9,7 @@ import java.net.InetAddress
import java.net.NetworkInterface
import java.net.SocketException
data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String, val state: State) {
data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: Long, val state: State) {
enum class State {
INCOMPLETE, VALID, FAILED, DELETING
}
@@ -50,13 +51,13 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: String,
"NOARP" -> return emptyList() // skip
else -> throw IllegalArgumentException("Unknown state encountered: ${match.groupValues[7]}")
}
val result = IpNeighbour(ip, dev, lladdr, state)
val result = IpNeighbour(ip, dev, lladdr.macToLong(), state)
val devParser = devFallback.matchEntire(dev)
if (devParser != null) try {
val index = devParser.groupValues[1].toInt()
val iface = NetworkInterface.getByIndex(index)
if (iface == null) Timber.w("Failed to find network interface #$index")
else return listOf(IpNeighbour(ip, iface.name, lladdr, state), result)
else return listOf(IpNeighbour(ip, iface.name, lladdr.macToLong(), state), result)
} catch (_: SocketException) { }
listOf(result)
} catch (e: Exception) {