تبدیل یک IP به HostName و بلعکس
using System.Net;
public string ConvertIP2HostName(string ip)
{
IPHostEntry iphost = Dns.GetHostEntry(ip);
return iphost.HostName;
}
public string HostNameToIP(string hostName)
{
IPHostEntry iphost = System.Net.Dns.GetHostEntry(hostName);
IPAddress addresses = iphost.AddressList;
StringBuilder addressList = new StringBuilder();
foreach (IPAddress address in addresses)
{
addressList.AppendFormat(“IP Address: {0};”, address.ToString());
} return addressList.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show( Class4.ConvertIP2HostName(“127.0.0.1”));
MessageBox.Show(Class4.HostNameToIP(“laptop”));
}