View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.tools;
12  
13  import java.io.IOException;
14  import java.net.InetAddress;
15  
16  import org.junit.jupiter.api.Assertions;
17  import org.junit.jupiter.api.Disabled;
18  import org.junit.jupiter.api.Test;
19  
20  import psiprobe.tools.Whois.Response;
21  
22  /**
23   * The Class WhoisTests.
24   */
25  class WhoisTests {
26  
27    /**
28     * Test localhost.
29     *
30     * @throws IOException Signals that an I/O exception has occurred.
31     */
32    // TODO breaks with latest surefire versions
33    @Disabled
34    @Test
35    void localhostTest() throws IOException {
36      int a = 127;
37      int b = 0;
38      int c = 0;
39      int d = 1;
40      String dotted = a + "." + b + "." + c + "." + d;
41      byte[] bytes = {(byte) a, (byte) b, (byte) c, (byte) d};
42  
43      Response response = Whois.lookup("whois.arin.net", 43, "n " + dotted, 5);
44      Assertions.assertEquals("SPECIAL-IPV4-LOOPBACK-IANA-RESERVED",
45          response.getData().get("NetName"));
46      Assertions.assertEquals("127.0.0.1", InetAddress.getByName(dotted).getHostName());
47      Assertions.assertEquals("127.0.0.1", InetAddress.getByAddress(bytes).getHostName());
48    }
49  
50    /**
51     * Test google.
52     *
53     * @throws IOException Signals that an I/O exception has occurred.
54     */
55    // TODO breaks with latest surefire versions
56    @Disabled
57    @Test
58    void googleTest() throws IOException {
59      int a = 74;
60      int b = 125;
61      int c = 45;
62      int d = 100;
63      String dotted = a + "." + b + "." + c + "." + d;
64      byte[] bytes = {(byte) a, (byte) b, (byte) c, (byte) d};
65  
66      Response response = Whois.lookup("whois.arin.net", 43, "n " + dotted, 5);
67      Assertions.assertEquals("GOOGLE", response.getData().get("NetName"));
68      Assertions.assertEquals("74.125.45.100", InetAddress.getByName(dotted).getHostName());
69      Assertions.assertEquals("74.125.45.100", InetAddress.getByAddress(bytes).getHostName());
70    }
71  
72  }