Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to find my public ip using MFC,which i can see from the www.whatismyip.com/[^]
is there a way to find it programmatically?
Thanks in advance
Posted

Hi you can follow the below steps to find public ip programmatically

public string GetLanIPAddress()
{
//Get the Host Name
string stringHostName = Dns.GetHostName();
//Get The Ip Host Entry
IPHostEntry ipHostEntries = Dns.GetHostEntry(stringHostName);
//Get The Ip Address From The Ip Host Entry Address List
IPAddress[] arrIpAddress = ipHostEntries.AddressList;
return arrIpAddress[arrIpAddress.Length - 1].ToString();
}

//Get The Lan Ip Address
string strLanIpAddress = GetLanIPAddress();

If you want to check public ip address you can visit this site
Ip-details.com
 
Share this answer
 
Comments
Gennady46 20-May-15 1:33am    
Which files should be included? I have built it, it says Dns undeclared?
 
Share this answer
 
Comments
anonymous1310 31-Jul-11 12:45pm    
thanks for the answer but that is my system ip (local ip) , what i want is my network ip .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900