Addressed an exception that was thrown because InetAddress.getLocalHost().hostAddress might get an ipv6 address

This commit is contained in:
Cyenoch 2020-03-11 22:58:44 +08:00
parent b8f49b5037
commit 6e7872e786

View File

@ -18,7 +18,7 @@ import kotlinx.io.pool.useInstance
import net.mamoe.mirai.utils.io.ByteArrayPool
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.net.InetAddress
import java.net.Inet4Address
import java.security.MessageDigest
import java.util.zip.Deflater
import java.util.zip.Inflater
@ -81,7 +81,7 @@ actual object MiraiPlatformUtils {
* Localhost 解析
*/
actual fun localIpAddress(): String = runCatching {
InetAddress.getLocalHost().hostAddress
Inet4Address.getLocalHost().hostAddress
}.getOrElse { "192.168.1.123" }
fun md5(stream: InputStream): ByteArray {