Csharp/C Sharp by API/System.Net/IPAddress

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

IPAddress.Any

using System;
using System.Net;
class MainClass
{
    public static void Main()
    {
        IPAddress test = IPAddress.Any;
        Console.WriteLine(test);
    }
}


IPAddress.Broadcast

using System;
using System.Net;
class MainClass
{
    public static void Main()
    {
        IPAddress test = IPAddress.Broadcast;
        Console.WriteLine(test);
    }
}


IPAddress.HostToNetworkOrder()

using System;
using System.Net;
using System.Text;
class MainClass
{
   public static void Main()
   {
      short test1 = 45;
      int test2 = 314159;
      long test3 = -123456789033452;
      byte[] data = new byte[1024];
      string output;
      short test1b = IPAddress.HostToNetworkOrder(test1);
      data = BitConverter.GetBytes(test1b);
      output = BitConverter.ToString(data);
      Console.WriteLine("test1 = {0}, nbo = {1}", test1b, output);
      int test2b = IPAddress.HostToNetworkOrder(test2);
      data = BitConverter.GetBytes(test2b);
      output = BitConverter.ToString(data);
      Console.WriteLine("test2 = {0}, nbo = {1}", test2b, output);
      long test3b = IPAddress.HostToNetworkOrder(test3);
      data = BitConverter.GetBytes(test3b);
      output = BitConverter.ToString(data);
      Console.WriteLine("test3 = {0}, nbo = {1}", test3b, output);
   }
}


IPAddress.IsLoopback

using System;
using System.Net;
class MainClass
{
    public static void Main()
    {
      IPAddress test2 = IPAddress.Loopback;
      if (IPAddress.IsLoopback(test2))
          Console.WriteLine("The Loopback address is: {0}", test2.ToString());
      else
          Console.WriteLine("Error obtaining the loopback address");
    }
}


IPAddress.Loopback

using System;
using System.Net;
class MainClass
{
    public static void Main()
    {
        IPAddress test = IPAddress.Loopback;
        Console.WriteLine(test);
    }
}


IPAddress.None

using System;
using System.Net;
class MainClass
{
    public static void Main()
    {
        IPAddress test = IPAddress.None;
        Console.WriteLine(test);
    }
}


IPAddress.Parse(String ipAddress)

using System;
using System.Net;
class MainClass
{
    public static void Main()
    {
        IPAddress test1 = IPAddress.Parse("192.168.1.1");
        Console.WriteLine(test1);
    }
}