Program.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using STUN.Utils;
  2. using System;
  3. using System.Net;
  4. using System.Threading.Tasks;
  5. namespace NatTypeTester_Console
  6. {
  7. internal static class Program
  8. {
  9. /// <summary>
  10. /// stun.qq.com 3478 0.0.0.0:0
  11. /// </summary>
  12. private static async Task Main(string[] args)
  13. {
  14. var server = @"stun.syncthing.net";
  15. ushort port = 3478;
  16. IPEndPoint local = null;
  17. if (args.Length > 0 && (Uri.CheckHostName(args[0]) == UriHostNameType.Dns || IPAddress.TryParse(args[0], out _)))
  18. {
  19. server = args[0];
  20. }
  21. if (args.Length > 1)
  22. {
  23. ushort.TryParse(args[1], out port);
  24. }
  25. if (args.Length > 2)
  26. {
  27. local = NetUtils.ParseEndpoint(args[2]);
  28. }
  29. var res = await NetUtils.NatBehaviorDiscovery(server, port, local);
  30. Console.WriteLine($@"Other address is {res.OtherEndPoint}");
  31. Console.WriteLine($@"Binding test: {res.BindingTestResult}");
  32. Console.WriteLine($@"Local address: {res.LocalEndPoint}");
  33. Console.WriteLine($@"Mapped address: {res.PublicEndPoint}");
  34. Console.WriteLine($@"Nat mapping behavior: {res.MappingBehavior}");
  35. Console.WriteLine($@"Nat filtering behavior: {res.FilteringBehavior}");
  36. }
  37. }
  38. }