This documentation is archived and is not being maintained.

IPAddress.IsLoopback Method

Indicates whether the specified IP address is the loopback address.

Namespace:  System.Net
Assembly:  System (in System.dll)

public static function IsLoopback(
	address : IPAddress
) : boolean


Type: System.Net.IPAddress

An IP address.

Return Value

Type: System.Boolean
true if address is the loopback address; otherwise, false.

The IsLoopback method compares address to Loopback and returns true if the two IP addresses are the same.

In the case of IPv4, that the IsLoopback method returns true for any IP address of the form 127.X.Y.Z (where X, Y, and Z are in the range 0-255), not just Loopback (

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

No code example is currently available or this language may not be supported.
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;

// This method calls the IPAddress::Parse method to check if the
// passed ipAddress parameter is in the correct format.
// Then it checks whether it represents a loopback address.
// Finally, it displays the results.
void parse(String* ipAddress) {
   String* loopBack=S" is not a loopback address.";
   try {
      // Perform syntax check by parsing the address string entered by the user.
      IPAddress* address = IPAddress::Parse(ipAddress);

      // Perform semantic check by verifying that the address is a valid IPv4
      // or IPv6 loopback address.
      if (IPAddress::IsLoopback(address)&&
         address->AddressFamily == AddressFamily::InterNetworkV6)
         loopBack = String::Concat(S" is an IPv6 loopback address whose internal format is: ", address, S".");
         if (IPAddress::IsLoopback(address) &&
            address->AddressFamily == AddressFamily::InterNetwork)
            loopBack = String::Concat(S" is an IPv4 loopback address whose internal format is: ", address, S".");

      // Display the results.
      Console::WriteLine(S"Your input address: \" {0} \" {1}", ipAddress, loopBack);
   } catch (FormatException* e) {
      Console::WriteLine(S"FormatException caught!!!");
      Console::WriteLine(S"Source : {0}", e->Source);
      Console::WriteLine(S"Message : {0}", e->Message);
   } catch (Exception* e) {
      Console::WriteLine(S"Exception caught!!!");
      Console::WriteLine(S"Source : {0}", e->Source);
      Console::WriteLine(S"Message : {0}", e->Message);

int main() {
   String* args[] = Environment::GetCommandLineArgs();
   if (args->Length == 1) {
      // No parameters entered. Display program usage.
      Console::WriteLine(S"Please enter an IP address.");
      Console::WriteLine(S"Usage:   >ipaddress_isloopback any IPv4 or IPv6 address.");
      Console::WriteLine(S"Example: >ipaddress_isloopback");
      Console::WriteLine(S"Example: >ipaddress_isloopback 0:0:0:0:0:0:0:1");
   } else
      // Parse the address string entered by the user.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0