I want to check if the upd port for OpenVPN is open. For Tcp Port it was really simple, but now I struggle with Udp ports.
This is my TCP Implementation
private static bool TestConnectionInternal(string hostname, int port, int timeOutMs, int maxTries, int count)
{
using (var tcpClient = new TcpClient())
{
try
{
Task result = tcpClient.ConnectAsync(hostname, port);
return result.Wait(timeOutMs);
}
catch (Exception e)
{
count += 1;
if (count < maxTries)
{
return TestConnectionInternal(hostname, port, timeOutMs, maxTries, count);
}
return false;
}
}
}