IPAddress Class

Provides an Internet Protocol (IP) address.

IsIPv6GlobalUnicast Method

public bool IsIPv6GlobalUnicast()

Description

Determines whether the IP address is a global unicast address.

Global unicast addresses are the IPv6 equivalent of public IPv4 addresses. They are routable on the Internet.

Syntax


public bool IsIPv6GlobalUnicast();
            

Parameters

This method has no parameters.

Return Value

true if the IP address is a global unicast address; otherwise, false.

Remarks

A global unicast address is any IPv6 address that is not:

  • A loopback address (::1).
  • A link-local address (starts with fe80::).
  • A multicast address (starts with ff00::).
  • A site-local address (deprecated, now unique local addresses fc00::/7).
  • An unspecified address (::).

This method is useful for validating if an IPv6 address is suitable for use on the public internet.

Examples

Example 1: Checking common IPv6 addresses


using System;

public class Example
{
    public static void Main()
    {
        // Global Unicast Address
        IPAddress ipGlobal = IPAddress.Parse("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
        Console.WriteLine($"'{ipGlobal}' is Global Unicast: {ipGlobal.IsIPv6GlobalUnicast()}"); // Output: True

        // Loopback Address
        IPAddress ipLoopback = IPAddress.Loopback; // ::1
        Console.WriteLine($"'{ipLoopback}' is Global Unicast: {ipLoopback.IsIPv6GlobalUnicast()}"); // Output: False

        // Link-Local Address
        IPAddress ipLinkLocal = IPAddress.Parse("fe80::1");
        Console.WriteLine($"'{ipLinkLocal}' is Global Unicast: {ipLinkLocal.IsIPv6GlobalUnicast()}"); // Output: False

        // Unspecified Address
        IPAddress ipUnspecified = IPAddress.Any; // ::
        Console.WriteLine($"'{ipUnspecified}' is Global Unicast: {ipUnspecified.IsIPv6GlobalUnicast()}"); // Output: False
    }
}
                

Example 2: Checking an IPv4-mapped IPv6 address


using System;

public class Example
{
    public static void Main()
    {
        // IPv4-mapped IPv6 address for 192.168.1.1
        IPAddress ipMapped = IPAddress.Parse("::ffff:c0a8:101");
        Console.WriteLine($"'{ipMapped}' is Global Unicast: {ipMapped.IsIPv6GlobalUnicast()}"); // Output: False
    }
}
                

Note: IPv4-mapped IPv6 addresses are not considered global unicast addresses by this method.

Requirements

Namespace: System.Net

Assembly: System.Net.Primitives (in .NET Core and .NET 5+) or System (in .NET Framework)