Wednesday, July 16, 2008

Get IP address in Windows MObile

Hi Guys,

Get IP address of the device, when they connected to network.

private void GetMyIP()
{
IPHostEntry hostentry = Dns.GetHostEntry(Dns.GetHostName());
if (hostentry != null)
{
IPAddress[] collectionOfIPs = hostentry.AddressList;
MessageBox.Show(collectionOfIPs[0].ToString());
}
}

Thank you

3 comments:

Ricardo Lopes said...

hi!! what references do you use for IPHostEntry , dns and IPAdress.

this is one of the errors.
"The type or namespace name 'IPHostEntry' could not be found (are you missing a using directive or an assembly reference?)"


thank you

SergioAFeo said...

you have to add the namespace System.Net to your "using" list.

Rahmad Hidayat said...

thanks my man, your article realy helpfull for me