Skip to content

Instantly share code, notes, and snippets.

@sajjadyousefnia
Created June 18, 2024 22:35
Show Gist options
  • Save sajjadyousefnia/cf26f4b58075f6b5d6032a8c2d1a8ef1 to your computer and use it in GitHub Desktop.
Save sajjadyousefnia/cf26f4b58075f6b5d6032a8c2d1a8ef1 to your computer and use it in GitHub Desktop.
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