forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhoisClientEx.java
More file actions
39 lines (27 loc) · 972 Bytes
/
WhoisClientEx.java
File metadata and controls
39 lines (27 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.zetcode;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
// probing whois.iana.org might give the right
// whois server
public class WhoisClientEx {
public static void main(String[] args) throws IOException {
var domainName = "example.com";
var whoisServer = "whois.nic.me";
int port = 43;
try (var socket = new Socket(whoisServer, port)) {
try (var writer = new PrintWriter(socket.getOutputStream(), true)) {
writer.println(domainName);
try (var reader = new BufferedReader(
new InputStreamReader(socket.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}
}
}
}