Hi,
Use Environment.Mac hineName 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(b ool localPreference )
{
return FindIPAddress(D ns.GetHostEntry (Dns.GetHostNam e()),
localPreference );
}
public static IPAddress FindIPAddress(I PHostEntry host, bool
localPreference )
{
if (host == null)
throw new ArgumentNullExc eption("host");
if (host.AddressLi st.Length == 1)
return host.AddressLis t[0];
else
{
foreach (System.Net.IPA ddress address in host.AddressLis t)
{
bool local = IsLocal(address );
if (local && localPreference )
return address;
else if (!local && !localPreferenc e)
return address;
}
return host.AddressLis t[0];
}
}
public static bool IsLocal(IPAddre ss address)
{
if (address == null)
throw new ArgumentNullExc eption("address ");
byte[] addr = address.GetAddr essBytes();
return addr[0] == 10
|| (addr[0] == 192 && addr[1] == 168)
|| (addr[0] == 172 && addr[1] >= 16 && addr[1] <= 31);
}
#endregion
}
--
Dave Sexton
"Hooyoo" <zh*********@12 6.comwrote in message
news:11******** **************@ l12g2000cwl.goo glegroups.com.. .
Hi, here,
How to get local machine name and IP address?
Thanks.