J'ai mis à jour le code "Jason Heine" (je ne sais pas comment étiqueter un nom) en C++. maintenant ça devrait marcher. à propos, à lui. donc ce que je reçois:
using namespace System;
using namespace System::Net;
void main(){
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);
array<IPAddress^> ^addr = ipEntry->AddressList;
for (int i = 0; i < addr->Length; i++)
{
Console::WriteLine("IP Address {0}: {1} ", i, addr[i]->ToString());
}
Console::ReadKey();
}
J'espère que cela vous aidera.
Testé sur mon PC avec wifi et LAN connecten et peu de cars virtuels pour "VMware Player" et je reçois 4 IPv6 et puis foloved par 4 IPv4. Si vous n'avez besoin que d'IPv4, vous pouvez utiliser:
using namespace System;
using namespace System::Net;
void main(){
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);
array<IPAddress^> ^addr = ipEntry->AddressList;
for (int i = 0; i < addr->Length; i++)
{
if(addr[i]->ToString()->Length < 20){
Console::WriteLine("IP Address {0}: {1} ", i, addr[i]->ToString());
}
}
Console::ReadKey();
}
Ensuite, je reçois seulement IPv4. juste des chiffres commencent à partir de 4. Mais pour moi c'est ok. vous pouvez ajouter une nouvelle variable pour recalculer la numérotation :)