6992685b86
Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
23 lines
454 B
C#
23 lines
454 B
C#
using System;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
|
|
namespace MonoTests.Helpers {
|
|
|
|
public static class NetworkHelpers
|
|
{
|
|
public static int FindFreePort ()
|
|
{
|
|
TcpListener l = new TcpListener(IPAddress.Loopback, 0);
|
|
l.Start();
|
|
int port = ((IPEndPoint)l.LocalEndpoint).Port;
|
|
l.Stop();
|
|
return port;
|
|
}
|
|
public static IPEndPoint LocalEphemeralEndPoint ()
|
|
{
|
|
return new IPEndPoint (IPAddress.Loopback, FindFreePort());
|
|
}
|
|
}
|
|
}
|