Ho bisogno di sapere come ottenere tutte le interfacce di rete con il loro indirizzo IPv4. O semplicemente wireless e Ethernet.Come faccio ad avere l'interfaccia di rete e il suo indirizzo IPv4 giusto?
Per ottenere tutte le interfacce dettagli della rete che uso questo:
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) {
if(ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) {
Console.WriteLine(ni.Name);
}
}
E per ottenere i tutti gli indirizzi IPv4 ospitate del computer:
IPAddress [] IPS = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress ip in IPS) {
if (ip.AddressFamily == AddressFamily.InterNetwork) {
Console.WriteLine("IP address: " + ip);
}
}
ma come ottenere l'interfaccia di rete e il suo giusto indirizzo IPv4?
Si prega di leggere un un po 'più attentamente. Vedere [GetIPProperties] (http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getipproperties.aspx) –
@JohnSaunders bene ho controllato il tuo link leggerlo .. e provato. ma non ho ricevuto l'indirizzo IPV4 !! come 192.168.1.25 !! –
Ok, è un po 'più sottile di quanto pensassi. Vedere [IPGlobalProperties.GetUnicastAddresses] (http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipglobalproperties.getunicastaddresses.aspx) –