mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-30 01:34:08 +00:00
Some checks failed
release Linux / build (push) Has been cancelled
release Linux / build and release deb x64 & arm64 (push) Has been cancelled
release Linux / build and release rpm x64 & arm64 (push) Has been cancelled
release Linux / build and release rpm riscv64 (push) Has been cancelled
release macOS / build (push) Has been cancelled
release Windows desktop (Avalonia UI) / build (push) Has been cancelled
release Windows / build (push) Has been cancelled
release Linux / release-zip (push) Has been cancelled
release macOS / release-zip (push) Has been cancelled
release macOS / package and release macOS dmg (push) Has been cancelled
release Windows desktop (Avalonia UI) / release-zip (push) Has been cancelled
release Windows / release-zip (push) Has been cancelled
52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
namespace ServiceLib.UdpTest.Tester;
|
|
|
|
public class StunService : IUdpTest
|
|
{
|
|
private const int StunDefaultPort = 3478;
|
|
private const string StunDefaultServer = "stun.voztovoice.org";
|
|
|
|
private static readonly byte[] StunBindingRequestPacket =
|
|
[
|
|
// STUN Binding Request
|
|
0x00, 0x01, // Message Type: Binding Request (0x0001)
|
|
0x00, 0x00, // Message Length: 0 (no attributes)
|
|
0x21, 0x12, 0xA4, 0x42, // Magic Cookie: 0x2112A442
|
|
// Transaction ID: 96 bits (12 bytes) random
|
|
0x66, 0x0E, 0xAB, 0xBC, 0x61, 0x0D,
|
|
0xA4, 0x40, 0x8C, 0x65, 0xC1, 0xBE,
|
|
];
|
|
|
|
public byte[] BuildUdpRequestPacket()
|
|
{
|
|
return (byte[])StunBindingRequestPacket.Clone();
|
|
}
|
|
|
|
public bool VerifyAndExtractUdpResponse(byte[] stunResponseBytes)
|
|
{
|
|
if (stunResponseBytes.Length < 20)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (stunResponseBytes.Length >= 2)
|
|
{
|
|
var messageType = (stunResponseBytes[0] << 8) | stunResponseBytes[1];
|
|
if (messageType is 0x0101 or 0x0111)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public ushort GetDefaultTargetPort()
|
|
{
|
|
return StunDefaultPort;
|
|
}
|
|
|
|
public string GetDefaultTargetHost()
|
|
{
|
|
return StunDefaultServer;
|
|
}
|
|
}
|