Csharp/C Sharp by API/System.Net/Dns — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
Содержание
Dns.EndResolve(IAsyncResult ar)
using System;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;
class MainClass
{
private static void Resolved(IAsyncResult ar)
{
string buffer;
IPHostEntry iphe = Dns.EndResolve(ar);
buffer = "Host name: " + iphe.HostName;
Console.WriteLine(buffer);
foreach(string alias in iphe.Aliases)
{
buffer = "Alias: " + alias;
Console.WriteLine(buffer);
}
foreach(IPAddress addrs in iphe.AddressList)
{
buffer = "Address: " + addrs.ToString();
Console.WriteLine(buffer);
}
}
public static void Main()
{
AsyncCallback OnResolved;
OnResolved = new AsyncCallback(Resolved);
string addr = "www.nfex.ru";
Object state = new Object();
Dns.BeginResolve(addr, OnResolved, state);
}
}
Dns.GetHostByAddress(IPAddress ip)
using System;
using System.Net;
class MainClass
{
public static void Main(string[] argv)
{
IPAddress test = IPAddress.Parse("64.200.123.1");
IPHostEntry iphe = Dns.GetHostByAddress(test);
foreach(string alias in iphe.Aliases)
{
Console.WriteLine("Alias: {0}", alias);
}
}
}
Dns.GetHostByName
using System;
using System.Net;
class MainClass
{
public static void Main()
{
IPHostEntry ihe = Dns.GetHostByName(Dns.GetHostName());
IPAddress myself = ihe.AddressList[0];
Console.WriteLine(myself);
}
}
Dns.GetHostEntry(String value)
using System;
using System.Net;
class MainClass
{
public static void Main(string[] args)
{
foreach (string comp in args)
{
try
{
IPAddress[] addresses = Dns.GetHostEntry(comp).AddressList;
foreach (IPAddress address in addresses)
{
Console.WriteLine("{0} = {1} ({2})",
comp, address, address.AddressFamily);
}
}
catch (Exception ex)
{
Console.WriteLine("{0} = Error ({1})", comp, ex.Message);
}
}
}
}
Dns.GetHostName()
using System;
using System.Net;
class MainClass
{
public static void Main()
{
Console.WriteLine(Dns.GetHostName());
}
}
Dns.Resolve
using System;
using System.Net;
class MainClass
{
public static void Main(string[] argv)
{
IPHostEntry iphe = Dns.Resolve("62.208.12.1");
Console.WriteLine("Host name: {0}", iphe.HostName);
foreach(string alias in iphe.Aliases)
{
Console.WriteLine("Alias: {0}", alias);
}
foreach(IPAddress address in iphe.AddressList)
{
Console.WriteLine("Address: {0}",
address.ToString());
}
}
}