Get the server name and ip address in C# 2010
I want to get the IP address of the server. The following code comes from:
public static void DoGetHostEntry(string hostname)
{
IPHostEntry host;
host = Dns.GetHostEntry(hostname);
MessageBox.Show("GetHostEntry({0}) returns:"+ hostname);
foreach (IPAddress ip in host.AddressList)
{
MessageBox.Show(" {0}"+ ip.ToString());
}
}
This code must know the name of the server computer.
AddressFamily in System.Net.IPAddress
System.Net.IPAddress i;
string HostName = i.AddressFamily.ToString();
Error ------------->Use of unassigned local variable 'i'
How can I get the name of the server computer?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…