Suppress links for bogon IPs
ipinfo.io does not tell a lot of information about bogon IP addresses, so let us just not show any links at all.
This commit is contained in:
@@ -55,7 +55,7 @@ open class Client(val mac: Long, val iface: String) {
|
||||
SpannableStringBuilder().apply {
|
||||
if (!record?.nickname.isNullOrEmpty()) appendln(macIface)
|
||||
ip.entries.forEach { (ip, state) ->
|
||||
append(makeIpSpan(ip.hostAddress))
|
||||
append(makeIpSpan(ip))
|
||||
appendln(app.getText(when (state) {
|
||||
IpNeighbour.State.INCOMPLETE -> R.string.connected_state_incomplete
|
||||
IpNeighbour.State.VALID -> R.string.connected_state_valid
|
||||
|
||||
@@ -50,25 +50,24 @@ fun setVisibility(view: View, value: Boolean) {
|
||||
view.isVisible = value
|
||||
}
|
||||
|
||||
fun makeIpSpan(ip: String) = SpannableString(ip).apply {
|
||||
if (app.hasTouch) {
|
||||
val filteredIp = ip.split('%', limit = 2).first()
|
||||
setSpan(CustomTabsUrlSpan("https://ipinfo.io/$filteredIp"), 0, filteredIp.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
}
|
||||
fun makeMacSpan(mac: String) = SpannableString(mac).apply {
|
||||
if (app.hasTouch) {
|
||||
setSpan(CustomTabsUrlSpan("https://macvendors.co/results/$mac"), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
fun makeIpSpan(ip: InetAddress) = ip.hostAddress.let {
|
||||
// exclude all bogon IP addresses supported by Android APIs
|
||||
if (app.hasTouch && !(ip.isMulticastAddress || ip.isAnyLocalAddress || ip.isLoopbackAddress ||
|
||||
ip.isLinkLocalAddress || ip.isSiteLocalAddress || ip.isMCGlobal || ip.isMCNodeLocal ||
|
||||
ip.isMCLinkLocal || ip.isMCSiteLocal || ip.isMCOrgLocal)) SpannableString(it).apply {
|
||||
setSpan(CustomTabsUrlSpan("https://ipinfo.io/$it"), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
} else it
|
||||
}
|
||||
fun makeMacSpan(mac: String) = if (app.hasTouch) SpannableString(mac).apply {
|
||||
setSpan(CustomTabsUrlSpan("https://macvendors.co/results/$mac"), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
} else mac
|
||||
|
||||
fun NetworkInterface.formatAddresses() = SpannableStringBuilder().apply {
|
||||
try {
|
||||
hardwareAddress?.apply { appendln(makeMacSpan(asIterable().macToString())) }
|
||||
} catch (_: SocketException) { }
|
||||
for (address in interfaceAddresses) {
|
||||
append(makeIpSpan(address.address.hostAddress))
|
||||
append(makeIpSpan(address.address))
|
||||
appendln("/${address.networkPrefixLength}")
|
||||
}
|
||||
}.trimEnd()
|
||||
|
||||
Reference in New Issue
Block a user