-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added WhoIsExample.kt added WhoIsResponse.kt added documentation removed RSAExample.kt (shouldn't be there) changed README.md
- Loading branch information
Showing
8 changed files
with
137 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
package me.lyzev.whois | ||
|
||
import com.google.gson.JsonParser | ||
import me.lyzev.whois.http.HttpClient | ||
import me.lyzev.whois.http.HttpMethod | ||
import me.lyzev.whois.response.WhoIsResponse | ||
|
||
class WhoIs(val domain: String) { | ||
|
||
fun doRequest() { | ||
val response = HttpClient.request(HttpMethod.GET, "https://data.iana.org/rdap/dns.json") | ||
/** | ||
* WhoIs is a simple library for querying whois information. | ||
* | ||
* @author Lyzev | ||
* @param hostname The hostname to query. | ||
*/ | ||
class WhoIs(val hostname: String) { | ||
|
||
/** | ||
* Queries whois information for the hostname. | ||
* | ||
* @return The whois information. | ||
*/ | ||
fun doRequest(): List<WhoIsResponse> { | ||
val response = HttpClient.request(HttpMethod.GET, "https://lookup.icann.org/api/whois?q=$hostname") | ||
val root = JsonParser.parseString(response.asString()).asJsonObject | ||
val whoIs = mutableListOf<WhoIsResponse>() | ||
root["records"].asJsonArray.forEach { whoIs += WhoIsResponse.from(it.asJsonObject) } | ||
return whoIs | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package me.lyzev.whois.response | ||
|
||
import com.google.gson.JsonObject | ||
|
||
/** | ||
* Represents a WHOIS response. | ||
* | ||
* @author Lyzev | ||
* @param domain the domain name | ||
* @param registryDomainID the registry domain ID | ||
* @param updatedDate the updated date | ||
* @param creationDate the creation date | ||
* @param referralURL the referral URL | ||
* @param registrar the registrar | ||
* @param registrant the registrant | ||
* @param admin the admin | ||
* @param tech the tech | ||
* @param nameservers the nameservers | ||
* @param lastWhoisDatabaseUpdate the last WHOIS database update | ||
* @param rawResponse the raw response | ||
*/ | ||
class WhoIsResponse private constructor( | ||
val domain: String, | ||
val registryDomainID: String, | ||
val updatedDate: String, | ||
val creationDate: String, | ||
val referralURL: String, | ||
val registrar: String, | ||
val registrant: String, | ||
val admin: String, | ||
val tech: String, | ||
val nameservers: List<String>, | ||
val lastWhoisDatabaseUpdate: String, | ||
val rawResponse: String | ||
) { | ||
|
||
/** | ||
* @return the raw response | ||
*/ | ||
override fun toString(): String = rawResponse | ||
|
||
companion object { | ||
|
||
/** | ||
* Creates a new instance of [WhoIsResponse] from the given [JsonObject]. | ||
* | ||
* @param jsonObject the JSON object | ||
* @return the new instance | ||
*/ | ||
fun from(root: JsonObject): WhoIsResponse { | ||
return WhoIsResponse( | ||
root["domainName"].run { if (isJsonNull) "null" else asString }, | ||
root["registryDomainID"].run { if (isJsonNull) "null" else asString }, | ||
root["updatedDate"].run { if (isJsonNull) "null" else asString }, | ||
root["creationDate"].run { if (isJsonNull) "null" else asString }, | ||
root["referralURL"].run { if (isJsonNull) "null" else asString }, | ||
root["registrar"].asJsonObject.get("registrar").run { if (isJsonNull) "null" else asString }, | ||
root["registrant"].asJsonObject.get("organization").run { if (isJsonNull) "null" else asString }, | ||
root["admin"].asJsonObject.get("organization").run { if (isJsonNull) "null" else asString }, | ||
root["tech"].asJsonObject.get("organization").run { if (isJsonNull) "null" else asString }, | ||
root["nameServer"].asJsonArray.map { it.run { if (isJsonNull) "null" else asString } }, | ||
root["lastWhoisDatabaseUpdate"].run { if (isJsonNull) "null" else asString }, | ||
root["serverResponse"].asJsonObject["rawResponse"].run { if (isJsonNull) "null" else asString } | ||
) | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package whois; | ||
|
||
import me.lyzev.whois.WhoIs; | ||
import me.lyzev.whois.response.WhoIsResponse; | ||
|
||
public class WhoIsExample { | ||
|
||
/** | ||
* AN example of how to use the library. | ||
*/ | ||
public static void main(String[] args) { | ||
WhoIs whoIs = new WhoIs("google.com"); | ||
whoIs.doRequest().forEach(System.out::println); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.lyzev.whois | ||
|
||
/** | ||
* AN example of how to use the library. | ||
*/ | ||
fun main() { | ||
val whoIs = WhoIs("google.com") | ||
whoIs.doRequest().forEach(::println) | ||
} |