Skip to content

Instantly share code, notes, and snippets.

@pelengami
Created March 22, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelengami/d934280614653174df7c8b9b3240599c to your computer and use it in GitHub Desktop.
Save pelengami/d934280614653174df7c8b9b3240599c to your computer and use it in GitHub Desktop.
Get available udp port
public bool TryGetAvailablePort(out int availableUdpPort)
{
var activeUdpListeners = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners();
var range = Enumerable.Range(5000, 6000);
availableUdpPort = range.First(p => activeUdpListeners.All(l => l.Port != p));
return availableUdpPort != -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment