How to check if UDP port is open or closed
<p>I want to iterate UDP port from 5000 to 50xx</p>

<p>How can I check if a specific port is already open or free to use?</p>

<p>I use this code but it always returns false:</p>

<pre><code>public bool PortIsUsed(int myport)
{
   bool alreadyinuse = (from p in System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners() where p.Port == myport select p).Count() == 1;
   return alreadyinuse;
}
</code></pre>
