Updated IPHub detection service

This commit is contained in:
bluefireoly
2020-10-31 15:22:31 +01:00
parent 7ad51fe006
commit a9532d8560
2 changed files with 11 additions and 5 deletions

View File

@@ -57,10 +57,7 @@ class BadIPDetector(
companion object { companion object {
val DEFAULT = BadIPDetector( val DEFAULT = BadIPDetector(
listOf( listOf(GetIPIntel())
GetIPIntel(),
IPHub()
)
) )
} }
@@ -101,11 +98,17 @@ abstract class BadIPDetectionService(
) { ) {
protected abstract fun requestString(ip: String): String protected abstract fun requestString(ip: String): String
protected open fun requestHeaders() = emptyMap<String, String>()
protected abstract fun interpreteResult(result: JSONObject): BadIPDetectionResult protected abstract fun interpreteResult(result: JSONObject): BadIPDetectionResult
fun isBad(ip: String): BadIPDetectionResult { fun isBad(ip: String): BadIPDetectionResult {
val response = khttp.get(requestString(ip))
val response = khttp.get(
requestString(ip),
headers = requestHeaders()
)
if (response.statusCode == 429) if (response.statusCode == 429)
return BadIPDetectionResult.LIMIT return BadIPDetectionResult.LIMIT
else { else {
@@ -123,6 +126,7 @@ abstract class BadIPDetectionService(
} }
} }
} }
} }

View File

@@ -8,10 +8,12 @@ import net.axay.kspigot.languageextensions.getStringOrNull
import org.json.JSONObject import org.json.JSONObject
class IPHub( class IPHub(
private val apiKey: String,
private val ifStrict: Boolean = false private val ifStrict: Boolean = false
) : BadIPDetectionService("iphub.info") { ) : BadIPDetectionService("iphub.info") {
override fun requestString(ip: String) = "http://v2.api.iphub.info/ip/$ip" 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 { override fun interpreteResult(result: JSONObject): BadIPDetectionResult {
val ifBlock = result.getStringOrNull("block")?.toInt() ?: return BadIPDetectionResult.ERROR val ifBlock = result.getStringOrNull("block")?.toInt() ?: return BadIPDetectionResult.ERROR