Created
June 18, 2024 22:35
-
-
Save sajjadyousefnia/cf26f4b58075f6b5d6032a8c2d1a8ef1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun sendPing(address: String): Boolean { | |
val policy = ThreadPolicy.Builder().permitAll().build() | |
StrictMode.setThreadPolicy(policy) | |
return try { | |
val inetAddress = InetAddress.getByName(address) | |
inetAddress.isReachable(5000) // Timeout in milliseconds (5 seconds) | |
} catch (e: Exception) { | |
false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment