Csharp/C Sharp by API/System.Net/IPAddress
Содержание
IPAddress.Any
<source lang="csharp"> using System; using System.Net; class MainClass {
public static void Main() { IPAddress test = IPAddress.Any; Console.WriteLine(test); }
}
</source>
IPAddress.Broadcast
<source lang="csharp"> using System; using System.Net; class MainClass {
public static void Main() { IPAddress test = IPAddress.Broadcast; Console.WriteLine(test); }
}
</source>
IPAddress.HostToNetworkOrder()
<source lang="csharp"> 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); }
}
</source>
IPAddress.IsLoopback
<source lang="csharp"> 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"); }
}
</source>
IPAddress.Loopback
<source lang="csharp"> using System; using System.Net; class MainClass {
public static void Main() { IPAddress test = IPAddress.Loopback; Console.WriteLine(test); }
}
</source>
IPAddress.None
<source lang="csharp"> using System; using System.Net; class MainClass {
public static void Main() { IPAddress test = IPAddress.None; Console.WriteLine(test); }
}
</source>
IPAddress.Parse(String ipAddress)
<source lang="csharp"> using System; using System.Net; class MainClass {
public static void Main() { IPAddress test1 = IPAddress.Parse("192.168.1.1"); Console.WriteLine(test1); }
}
</source>