I'm trying to create UDP port checker based on this question, however when testing (for example) www.google.com on port range 1-100, I receive for each port the exception "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond". Below is my code for testing the port:
try {
UdpClient udpClient = new UdpClient(Port);
Socket uSocket = udpClient.Client;
uSocket.ReceiveTimeout = 5000;
uSocket.Connect(Adress, Port);
udpClient.Connect(Adress, Port);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(Adress, Port);
Byte[] sendBytes = Encoding.ASCII.GetBytes("?");
udpClient.Send(sendBytes, sendBytes.Length);
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
} catch (SocketException e) {
if (e.ErrorCode == 10054) {
return false;
} else {
return false;
}
}
return true;