From a9532d85604a35a3511fe0fb286a2424789aebd9 Mon Sep 17 00:00:00 2001 From: bluefireoly Date: Sat, 31 Oct 2020 15:22:31 +0100 Subject: [PATCH] Updated IPHub detection service --- .../net/axay/kspigot/ipaddress/BadIPDetection.kt | 14 +++++++++----- .../ipaddress/badipdetectionservices/IPHub.kt | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/net/axay/kspigot/ipaddress/BadIPDetection.kt b/src/main/kotlin/net/axay/kspigot/ipaddress/BadIPDetection.kt index 94de9677..8a533775 100644 --- a/src/main/kotlin/net/axay/kspigot/ipaddress/BadIPDetection.kt +++ b/src/main/kotlin/net/axay/kspigot/ipaddress/BadIPDetection.kt @@ -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() 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( } } + } } \ No newline at end of file diff --git a/src/main/kotlin/net/axay/kspigot/ipaddress/badipdetectionservices/IPHub.kt b/src/main/kotlin/net/axay/kspigot/ipaddress/badipdetectionservices/IPHub.kt index 3a551909..55922c95 100644 --- a/src/main/kotlin/net/axay/kspigot/ipaddress/badipdetectionservices/IPHub.kt +++ b/src/main/kotlin/net/axay/kspigot/ipaddress/badipdetectionservices/IPHub.kt @@ -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