System.Net.IPAddress.IsUniqueLocalUnicast

Checks if an IP address is a unique local unicast address.

Overview

The IsUniqueLocalUnicast() method in the System.Net.IPAddress class is used to determine whether an IPv6 address is a unique local unicast address. These addresses, defined in RFC 4193, are intended for use within a local network and are not routable on the global internet. They are characterized by the prefix fc00::/7 (though fd00::/8 is the commonly implemented subset).

Method Signature

public bool IsUniqueLocalUnicast();

Parameters

This method takes no parameters.

Return Value

Remarks

A unique local unicast address is defined as an IPv6 address that falls within the fc00::/7 prefix range. The IsUniqueLocalUnicast() method simplifies the process of checking this specific address type without needing to manually parse the address bytes.

This method is only applicable to IPv6 addresses. If called on an IPv4 address, it will always return false.

Example

The following example demonstrates how to use the IsUniqueLocalUnicast() method:

using System;
using System.Net;

public class IpAddressChecker
{
    public static void Main(string[] args)
    {
        // Example unique local unicast IPv6 address
        string ipv6UniqueLocalAddressString = "fd12:3456:789a:1::1";
        IPAddress ipv6UniqueLocalAddress = IPAddress.Parse(ipv6UniqueLocalAddressString);

        if (ipv6UniqueLocalAddress.IsUniqueLocalUnicast())
        {
            Console.WriteLine($"{ipv6UniqueLocalAddressString} is a unique local unicast address.");
        }
        else
        {
            Console.WriteLine($"{ipv6UniqueLocalAddressString} is NOT a unique local unicast address.");
        }

        // Example non-unique local unicast IPv6 address (global unicast)
        string ipv6GlobalAddressString = "2001:db8::1";
        IPAddress ipv6GlobalAddress = IPAddress.Parse(ipv6GlobalAddressString);

        if (ipv6GlobalAddress.IsUniqueLocalUnicast())
        {
            Console.WriteLine($"{ipv6GlobalAddressString} is a unique local unicast address.");
        }
        else
        {
            Console.WriteLine($"{ipv6GlobalAddressString} is NOT a unique local unicast address.");
        }

        // Example IPv4 address
        string ipv4AddressString = "192.168.1.1";
        IPAddress ipv4Address = IPAddress.Parse(ipv4AddressString);

        if (ipv4Address.IsUniqueLocalUnicast())
        {
            Console.WriteLine($"{ipv4AddressString} is a unique local unicast address.");
        }
        else
        {
            Console.WriteLine($"{ipv4AddressString} is NOT a unique local unicast address.");
        }
    }
}

See Also

IPAddress Class

Represents an Internet Protocol (IP) address.

Namespace: System.Net

View Details

IsIPv6

Checks if the IP address is an IPv6 address.

Namespace: System.Net

View Details

IsIPv6Teredo

Checks if the IP address is a Teredo address.

Namespace: System.Net

View Details

IsIPv6Multicast

Checks if the IP address is an IPv6 multicast address.

Namespace: System.Net

View Details