Код: Выделить всё
String strHostName = string.Empty;
// Getting Ip address of local machine...
// First get the host name of local machine.
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
// Then using host name, get the IP address list..
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString());
}
Console.ReadLine();
Если я не подключен к сети, а подключен к Интернету напрямую через модем без роутера, то хотелось бы получить ошибку. Как я могу узнать, подключен ли мой компьютер к сети с помощью C#, и если да, то получить IP-адрес локальной сети.
Подробнее здесь: https://stackoverflow.com/questions/680 ... ip-address
Мобильная версия