Skip to content

Commit

Permalink
finished WhoIs.kt
Browse files Browse the repository at this point in the history
added WhoIsExample.kt
added WhoIsResponse.kt
added documentation
removed RSAExample.kt (shouldn't be there)
changed README.md
  • Loading branch information
Lyzev committed Apr 3, 2022
1 parent 73d43c8 commit 3199f99
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 33 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">WhoIs4K</h1>

<p align="center">A RSA Cipher implementation for Kotlin/Java.</p>
<p align="center">A library for who is requests.</p>

<div align="center">
<a href="https://discord.gg/5UmsQP4MFH"><img src="https://img.shields.io/discord/610120595765723137?logo=discord" alt="Discord"/></a>
Expand Down Expand Up @@ -83,7 +83,23 @@ dependencies {

### Example

Coming soon!
<details>
<summary>Kotlin</summary>

```kotlin
val whoIs = WhoIs("google.com")
whoIs.doRequest().forEach(::println)
```
</details>

<details>
<summary>Java</summary>

```java
WhoIs whoIs = new WhoIs("google.com");
whoIs.doRequest().forEach(System.out::println);
```
</details>

## Documentation

Expand All @@ -98,3 +114,9 @@ You can find the qodana report [here](https://lyzev.github.io/WhoIs4K/qodana).
Bug reports and suggestions should be made in this repo's [issue tracker](https://github.com/Lyzev/WhoIs4K/issues)
using the templates provided. Please provide as much information as you can to best help us understand your issue and
give a better chance of it being resolved.

## What is a WHOIS?
WHOIS (pronounced as the phrase "who is") is a query and response protocol that is widely used for querying databases that store the registered users or assignees of an Internet resource, such as a domain name, an IP address block or an autonomous system, but is also used for a wider range of other information. The protocol stores and delivers database content in a human-readable format. The current iteration of the WHOIS protocol was drafted by the Internet Society, and is documented in RFC 3912.

Source: [Wikipedia](https://en.wikipedia.org/wiki/WHOIS)
See [Wikipedia](https://en.wikipedia.org/wiki/WHOIS) for more information.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

dependencies {
implementation("com.google.code:gson:${project["gson_version"]}")
implementation("com.google.code.gson:gson:${project["gson_version"]}")
}

tasks.getByName<DokkaTask>("dokkaHtml") {
Expand Down
25 changes: 20 additions & 5 deletions src/main/kotlin/me/lyzev/whois/WhoIs.kt
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
}

}
2 changes: 1 addition & 1 deletion src/main/kotlin/me/lyzev/whois/http/HttpRequester.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object HttpRequester {
val paramaters = HttpParameterSetParser(parameters).asString()
request.append(paramaters)
val httpConnection = getConnection(request.toString(), *headers)
httpConnection.requestMethod = HttpMethod.GET.asString()
httpConnection.requestMethod = GET.asString()
return HttpRequest(httpConnection)
}

Expand Down
67 changes: 67 additions & 0 deletions src/main/kotlin/me/lyzev/whois/response/WhoIsResponse.kt
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 }
)
}
}
}
15 changes: 15 additions & 0 deletions src/test/java/whois/WhoIsExample.java
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);
}
}
24 changes: 0 additions & 24 deletions src/test/kotlin/me/lyzev/rsa/RSAExample.kt

This file was deleted.

9 changes: 9 additions & 0 deletions src/test/kotlin/me/lyzev/whois/WhoIsExample.kt
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)
}

0 comments on commit 3199f99

Please sign in to comment.