Updated IPHub detection service
This commit is contained in:
@@ -57,10 +57,7 @@ class BadIPDetector(
|
||||
|
||||
companion object {
|
||||
val DEFAULT = BadIPDetector(
|
||||
listOf(
|
||||
GetIPIntel(),
|
||||
IPHub()
|
||||
)
|
||||
listOf(GetIPIntel())
|
||||
)
|
||||
}
|
||||
|
||||
@@ -101,11 +98,17 @@ abstract class BadIPDetectionService(
|
||||
) {
|
||||
|
||||
protected abstract fun requestString(ip: String): String
|
||||
protected open fun requestHeaders() = emptyMap<String, String>()
|
||||
|
||||
protected abstract fun interpreteResult(result: JSONObject): BadIPDetectionResult
|
||||
|
||||
fun isBad(ip: String): BadIPDetectionResult {
|
||||
val response = khttp.get(requestString(ip))
|
||||
|
||||
val response = khttp.get(
|
||||
requestString(ip),
|
||||
headers = requestHeaders()
|
||||
)
|
||||
|
||||
if (response.statusCode == 429)
|
||||
return BadIPDetectionResult.LIMIT
|
||||
else {
|
||||
@@ -123,6 +126,7 @@ abstract class BadIPDetectionService(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -8,10 +8,12 @@ import net.axay.kspigot.languageextensions.getStringOrNull
|
||||
import org.json.JSONObject
|
||||
|
||||
class IPHub(
|
||||
private val apiKey: String,
|
||||
private val ifStrict: Boolean = false
|
||||
) : BadIPDetectionService("iphub.info") {
|
||||
|
||||
override fun requestString(ip: String) = "http://v2.api.iphub.info/ip/$ip"
|
||||
override fun requestHeaders() = mapOf("X-Key" to apiKey)
|
||||
|
||||
override fun interpreteResult(result: JSONObject): BadIPDetectionResult {
|
||||
val ifBlock = result.getStringOrNull("block")?.toInt() ?: return BadIPDetectionResult.ERROR
|
||||
|
Reference in New Issue
Block a user