Microsoft Docs

IPEndPoint Class

The System.Net.IPEndPoint class represents a network endpoint as an IP address and a port number.

Namespace

System.Net

Assembly

System.Net.Primitives.dll

Syntax

public class IPEndPoint : EndPoint
{
    public IPEndPoint(IPAddress address, int port);
    public IPAddress Address { get; set; }
    public int Port { get; set; }
    public override AddressFamily AddressFamily { get; }
    public override SocketAddress Serialize();
    public override EndPoint Create(SocketAddress socketAddress);
    public static IPEndPoint Parse(string s);
    public static bool TryParse(string s, out IPEndPoint result);
}

Properties

PropertyTypeDescription
AddressIPAddressGets or sets the IP address of the endpoint.
PortintGets or sets the port number of the endpoint.
AddressFamilyAddressFamilyGets the address family of the endpoint.

Methods

Examples

// Create an IPEndPoint from an IP address and a port.
IPAddress ip = IPAddress.Parse("192.168.1.100");
int port = 8080;
IPEndPoint endpoint = new IPEndPoint(ip, port);
Console.WriteLine($"Endpoint: {endpoint}");

// Parse from a string.
IPEndPoint parsed = IPEndPoint.Parse("10.0.0.5:5000");
Console.WriteLine($"Parsed: {parsed.Address} on port {parsed.Port}");

// TryParse usage.
if (IPEndPoint.TryParse("invalid:port", out IPEndPoint result))
{
    Console.WriteLine("Parsed successfully");
}
else
{
    Console.WriteLine("Failed to parse");
}

See Also