Skip to content

Commit f61c688

Browse files
committed
refactor: Update console example
1 parent 49fdbd9 commit f61c688

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

NatTypeTester-Console/Program.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Dns.Net.Clients;
2+
using STUN;
23
using STUN.Client;
34
using System;
45
using System.Net;
@@ -9,24 +10,22 @@ namespace NatTypeTester
910
internal static class Program
1011
{
1112
/// <summary>
12-
/// stun.qq.com 3478 0.0.0.0:0
13+
/// stun.qq.com:3478 0.0.0.0:0
1314
/// </summary>
1415
private static async Task Main(string[] args)
1516
{
1617
var server = @"stun.syncthing.net";
1718
ushort port = 3478;
18-
IPEndPoint? local = null;
19-
if (args.Length > 0 && (Uri.CheckHostName(args[0]) == UriHostNameType.Dns || IPAddress.TryParse(args[0], out _)))
19+
var local = new IPEndPoint(IPAddress.Any, 0);
20+
21+
if (args.Length > 0 && StunServer.TryParse(args[0], out var stun))
2022
{
21-
server = args[0];
23+
server = stun.Hostname;
24+
port = stun.Port;
2225
}
2326
if (args.Length > 1)
2427
{
25-
ushort.TryParse(args[1], out port);
26-
}
27-
if (args.Length > 2)
28-
{
29-
local = IPEndPoint.Parse(args[2]);
28+
IPEndPoint.TryParse(args[2], out local);
3029
}
3130

3231
using var client = new StunClient5389UDP(new DefaultDnsClient(), server, port, local);

0 commit comments

Comments
 (0)