C# IPAddress IsLoopback

Description

IPAddress IsLoopback Indicates whether the specified IP address is the loopback address.

Syntax

IPAddress.IsLoopback has the following syntax.


public static bool IsLoopback(
  IPAddress address
)

Parameters

IPAddress.IsLoopback has the following parameters.

  • address - An IP address.

Returns

IPAddress.IsLoopback method returns true if address is the loopback address; otherwise, false.

Example

The following code example uses the IsLoopback method to determine whether the specified address is a loopback address.


using System;/*from  w  w  w.  ja  v  a 2 s .com*/
using System.Net;
using System.Net.Sockets;

class IsLoopbackTest
{

  private static void Main(string[] args) 
  {
      string ipAddress = "127.0.0.1";

      IPAddress address = IPAddress.Parse(ipAddress);
      if(IPAddress.IsLoopback(address)&& address.AddressFamily == AddressFamily.InterNetworkV6)
        Console.WriteLine("yes IPV6");
      else 
        if(IPAddress.IsLoopback(address) && address.AddressFamily == AddressFamily.InterNetwork)
          Console.WriteLine("IPv4");
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient