Skip to content

Commit 08c4f12

Browse files
committed
Merge branch 'improve/handle-alt-JPNIC-res'
2 parents b296472 + a73137e commit 08c4f12

File tree

11 files changed

+425
-93
lines changed

11 files changed

+425
-93
lines changed

RELEASE-NOTES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v.5.1.0
2+
- Added parsing of alternative JPNIC response format (without key letters)
3+
- Fixed tests
4+
- Added ability to rethrow transport exceptions that've occurred during WHOIS request instead of swallowing them
5+
16
v.5.0.0
27
- Update the target frameworks
38
- Improvement: aware "whois: <server>" syntax for referral servers

Readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using Whois.NET;
2121
...
2222
private async Task QueryByIPAddress()
2323
{
24-
var result = await WhoisClient.QueryAsync("8.8.8.8");
24+
var result = await WhoisClient.QueryAsync("8.8.8.8", new WhoisQueryOptions());
2525

2626
Console.WriteLine("{0} - {1}", result.AddressRange.Begin, result.AddressRange.End); // "8.8.8.0 - 8.8.8.255"
2727
Console.WriteLine("{0}", result.OrganizationName); // "Google Inc. LVLT-GOGL-8-8-8 (NET-8-8-8-0-1)"
@@ -30,7 +30,7 @@ private async Task QueryByIPAddress()
3030

3131
private async Task QueryByDomain()
3232
{
33-
var result = await WhoisClient.QueryAsync("google.com");
33+
var result = await WhoisClient.QueryAsync("google.com", new WhoisQueryOptions());
3434

3535
Console.WriteLine("{0}", result.OrganizationName); // "Google Inc."
3636
Console.WriteLine(string.Join(" > ", result.RespondedServers)); // "whois.iana.org > whois.verisign-grs.com > whois.markmonitor.com"
@@ -44,7 +44,7 @@ using Whois.NET;
4444
...
4545
private void QueryByIPAddress()
4646
{
47-
var result = WhoisClient.Query("8.8.8.8");
47+
var result = WhoisClient.Query("8.8.8.8", new WhoisQueryOptions());
4848

4949
Console.WriteLine("{0} - {1}", result.AddressRange.Begin, result.AddressRange.End); // "8.8.8.0 - 8.8.8.255"
5050
Console.WriteLine("{0}", result.OrganizationName); // "Google Inc. LVLT-GOGL-8-8-8 (NET-8-8-8-0-1)"
@@ -53,7 +53,7 @@ private void QueryByIPAddress()
5353

5454
private async void QueryByDomain()
5555
{
56-
var result = WhoisClient.Query("google.com");
56+
var result = WhoisClient.Query("google.com", new WhoisQueryOptions());
5757

5858
Console.WriteLine("{0}", result.OrganizationName); // "Google Inc."
5959
Console.WriteLine(string.Join(" > ", result.RespondedServers)); // "whois.iana.org > whois.verisign-grs.com > whois.markmonitor.com"

WhoisClient.NET.Test/DomainTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class DomainTests
2020
[TestCase(@"facebook.com", @"Meta Platforms, Inc.")]
2121
public void WhoisClientTest(string domain, string expectedOrgName)
2222
{
23-
var response = WhoisClient.Query(domain);
23+
var response = WhoisClient.Query(domain, new WhoisQueryOptions());
2424
response.OrganizationName.Is(expectedOrgName);
2525
response.AddressRange.IsNull();
2626
}
@@ -29,7 +29,7 @@ public void WhoisClientTest(string domain, string expectedOrgName)
2929
[TestCase(@"google.com", @"Google LLC")]
3030
public async Task WhoisClientAsyncTest(string domain, string expectedOrgName)
3131
{
32-
var response = await WhoisClient.QueryAsync(domain);
32+
var response = await WhoisClient.QueryAsync(domain, new WhoisQueryOptions());
3333
response.OrganizationName.Is(expectedOrgName);
3434
response.AddressRange.IsNull();
3535
}

WhoisClient.NET.Test/IpTests.cs

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using System.Net.Sockets;
2+
using NUnit.Framework;
23
using Whois.NET;
34

45
namespace WhoisClient_NET.Test;
@@ -21,7 +22,7 @@ public class IpTests
2122
[TestCaseSource(nameof(IpTestCases))]
2223
public void WhoisClientTest(string ip, string expectedOrgName, string expectedAddressRange)
2324
{
24-
var response = WhoisClient.Query(ip);
25+
var response = WhoisClient.Query(ip, new WhoisQueryOptions());
2526
response.OrganizationName.Is(expectedOrgName);
2627
response.AddressRange.ToString().Is(expectedAddressRange);
2728
}
@@ -30,8 +31,100 @@ public void WhoisClientTest(string ip, string expectedOrgName, string expectedAd
3031
[TestCaseSource(nameof(IpTestCases))]
3132
public async Task WhoisClientAsyncTest(string ip, string expectedOrgName, string expectedAddressRange)
3233
{
33-
var response = await WhoisClient.QueryAsync(ip);
34+
var response = await WhoisClient.QueryAsync(ip, new WhoisQueryOptions());
3435
response.OrganizationName.Is(expectedOrgName);
3536
response.AddressRange.ToString().Is(expectedAddressRange);
3637
}
38+
39+
[Test]
40+
public void RawQuery_InvalidWhoisServerSpecified_TransportExceptionSwallowed()
41+
{
42+
var response = WhoisClient.RawQuery("4.4.4.4", new WhoisQueryOptions { Server = "unknown.server.pp" });
43+
44+
response.Is(string.Empty);
45+
}
46+
47+
[Test]
48+
public void RawQuery_InvalidWhoisServerSpecified_TransportExceptionRethrown()
49+
{
50+
TestDelegate action = () => WhoisClient.RawQuery("4.4.4.4", new WhoisQueryOptions
51+
{
52+
Server = "unknown.server.pp",
53+
RethrowExceptions = true
54+
});
55+
56+
var exception = Assert.Throws<AggregateException>(action)!;
57+
exception.InnerException.IsInstanceOf<SocketException>();
58+
}
59+
60+
[Test]
61+
public void Query_With3Retries_InvalidWhoisServerSpecified_TransportExceptionSwallowed()
62+
{
63+
var response = WhoisClient.Query("4.4.4.4", new WhoisQueryOptions
64+
{
65+
Server = "unknown.server.pp",
66+
Retries = 3
67+
});
68+
69+
response.Raw.Is(string.Empty);
70+
}
71+
72+
[Test]
73+
public void Query_With3Retries_InvalidWhoisServerSpecified_TransportExceptionRethrown()
74+
{
75+
TestDelegate action = () => WhoisClient.Query("4.4.4.4", new WhoisQueryOptions
76+
{
77+
Server = "unknown.server.pp",
78+
Retries = 3,
79+
RethrowExceptions = true
80+
});
81+
82+
var exception = Assert.Throws<AggregateException>(action)!;
83+
exception.InnerException.IsInstanceOf<SocketException>();
84+
}
85+
86+
[Test]
87+
public async Task RawQueryAsync_InvalidWhoisServerSpecified_TransportExceptionSwallowed()
88+
{
89+
var response = await WhoisClient.RawQueryAsync("4.4.4.4", new WhoisQueryOptions { Server = "unknown.server.pp" });
90+
91+
response.Is(string.Empty);
92+
}
93+
94+
[Test]
95+
public void RawQueryAsync_InvalidWhoisServerSpecified_TransportExceptionRethrown()
96+
{
97+
AsyncTestDelegate action = () => WhoisClient.RawQueryAsync("4.4.4.4", new WhoisQueryOptions
98+
{
99+
Server = "unknown.server.pp",
100+
RethrowExceptions = true
101+
});
102+
103+
Assert.ThrowsAsync<SocketException>(action);
104+
}
105+
106+
[Test]
107+
public async Task QueryAsync_With3Retries_InvalidWhoisServerSpecified_TransportExceptionSwallowed()
108+
{
109+
var response = await WhoisClient.QueryAsync("4.4.4.4", new WhoisQueryOptions
110+
{
111+
Server = "unknown.server.pp",
112+
Retries = 3
113+
});
114+
115+
response.Raw.Is(string.Empty);
116+
}
117+
118+
[Test]
119+
public void QueryAsync_With3Retries_InvalidWhoisServerSpecified_TransportExceptionRethrown()
120+
{
121+
AsyncTestDelegate action = () => WhoisClient.QueryAsync("4.4.4.4", new WhoisQueryOptions
122+
{
123+
Server = "unknown.server.pp",
124+
Retries = 3,
125+
RethrowExceptions = true
126+
});
127+
128+
Assert.ThrowsAsync<SocketException>(action);
129+
}
37130
}

WhoisClient.NET.Test/WhoisResponseTest.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,50 @@ public class WhoisResponseTest
1717
"m. [管理者連絡窓口] HH11825JP\r\n" +
1818
"n. [技術連絡担当者] MO5920JP\r\n";
1919

20+
private readonly string ResponseJPWithoutKeyLetters =
21+
"Network Information: [ネットワーク情報]\r\n" +
22+
"[IPネットワークアドレス] 27.80.0.0/12\r\n" +
23+
"[ネットワーク名]\r\n" +
24+
"[組織名] KDDI株式会社\r\n" +
25+
"[Organization] KDDI CORPORATION\r\n" +
26+
"[管理者連絡窓口] JP00000127\r\n" +
27+
"[技術連絡担当者] JP00000181\r\n" +
28+
"[Abuse] [email protected]\r\n" +
29+
"[割振年月日] 2010/04/28\r\n" +
30+
"[最終更新] 2010/04/28 10:50:55(JST)\r\n";
31+
2032
[Test]
2133
public void OrganizationNameTest_JP()
2234
{
2335
new WhoisResponse(null, this.ResponseJP)
2436
.OrganizationName.Is("社団法人 日本ネットワークインフォメーションセンター");
2537
}
2638

39+
[Test]
40+
public void OrganizationNameTest_JP_WithoutKeyLetters()
41+
{
42+
new WhoisResponse(null, this.ResponseJPWithoutKeyLetters)
43+
.OrganizationName.Is("KDDI株式会社");
44+
}
45+
2746
[Test]
2847
public void AddressRangeTest_JP()
2948
{
3049
var r = new WhoisResponse(null, this.ResponseJP);
50+
r.AddressRange.IsNotNull();
3151
r.AddressRange.Begin.ToString().Is("192.41.192.0");
3252
r.AddressRange.End.ToString().Is("192.41.192.255");
3353
}
3454

55+
[Test]
56+
public void AddressRangeTest_JP_WithoutKeyLetters()
57+
{
58+
var r = new WhoisResponse(null, this.ResponseJPWithoutKeyLetters);
59+
r.AddressRange.IsNotNull();
60+
r.AddressRange.Begin.ToString().Is("27.80.0.0");
61+
r.AddressRange.End.ToString().Is("27.95.255.255");
62+
}
63+
3564
private readonly string ResponseEN1 =
3665
"% [whois.apnic.net node-2]\r\n" +
3766
"% Whois data copyright terms http://www.apnic.net/db/dbcopyright.html\r\n" +
@@ -120,7 +149,7 @@ public void OrganizationNameTest_EN2()
120149
[Test]
121150
public void RespondedServersTest()
122151
{
123-
var WR = WhoisClient.Query("150.126.0.0");
152+
var WR = WhoisClient.Query("150.126.0.0", new WhoisQueryOptions());
124153
WR.RespondedServers.Length.Is(3);
125154
}
126155

WhoisClient.NET/EndPoint.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Whois.NET
2+
{
3+
internal class EndPoint
4+
{
5+
public string Host { get; }
6+
7+
public int Port { get; }
8+
9+
public EndPoint(string host, int port)
10+
{
11+
this.Host = host;
12+
this.Port = port;
13+
}
14+
}
15+
}

WhoisClient.NET/IQueryOptions.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Text;
2+
3+
namespace Whois.NET
4+
{
5+
internal interface IQueryOptions
6+
{
7+
/// <summary>
8+
/// Gets the encoding method to decode the result of query. This default value is ASCII encoding.
9+
/// </summary>
10+
Encoding Encoding { get; }
11+
12+
/// <summary>
13+
/// Gets a timespan to limit the connection attempt, in seconds. The default value is 600 seconds.
14+
/// </summary>
15+
int Timeout { get; }
16+
17+
/// <summary>
18+
/// Gets the number of times a connection will be attempted. The default value is 10.
19+
/// </summary>
20+
int Retries { get; }
21+
22+
/// <summary>
23+
/// Gets whether rethrow any caught exceptions instead of swallowing them. The default value is false.
24+
/// </summary>
25+
bool RethrowExceptions { get; }
26+
}
27+
}

WhoisClient.NET/WhoisClient.NET.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<RootNamespace>Whois.NET</RootNamespace>
99
<AssemblyName>WhoisClient</AssemblyName>
1010
<Product>WhoisClient.NET</Product>
11-
<Authors>J.Sakamoto, Keith J. Jones, Martijn Storck</Authors>
12-
<Version>5.0.0</Version>
13-
<Copyright>Copyright 2012-2023 J.Sakamoto; Copyright Keith J. Jones, 2016; Martijn Storck, 2023, Ms-PL License.</Copyright>
11+
<Authors>J.Sakamoto, Keith J. Jones, Martijn Storck, Makaopior</Authors>
12+
<Version>5.1.0</Version>
13+
<Copyright>Copyright 2012-2025 J.Sakamoto; 2016 Keith J. Jones; 2023 Martijn Storck; 2025 Makaopior; Ms-PL License.</Copyright>
1414
<PackageLicenseExpression>MS-PL</PackageLicenseExpression>
1515
<PackageProjectUrl>https://github.com/jsakamoto/WhoisClient.NET/</PackageProjectUrl>
1616
<Description>This library is a WHOIS protocol client used to search owner information by IP address or domain name.

0 commit comments

Comments
 (0)