Use Environment.MachineName to get the local machine's NetBIOS name.
Here's some code that will get one of the IP addresses assigned to the local
computer, accounting for multiple network adapters and scope (e.g., LAN,
WAN):
public static class Network
{
#region DNS
public static IPAddress FindIPAddress(bool localPreference)
{
return FindIPAddress(Dns.GetHostEntry(Dns.GetHostName()),
localPreference);
}
public static IPAddress FindIPAddress(IPHostEntry host, bool
localPreference)
{
if (host == null)
throw new ArgumentNullException("host");
if (host.AddressList.Length == 1)
return host.AddressList[0];
else
{
foreach (System.Net.IPAddress address in host.AddressList)
{
bool local = IsLocal(address);
if (local && localPreference)
return address;
else if (!local && !localPreference)
return address;
}
return host.AddressList[0];
}
}
public static bool IsLocal(IPAddress address)
{
if (address == null)
throw new ArgumentNullException("address");
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.