Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.20/5 (2 votes)
See more:
C#
public string Get_real_IP(string Provider)
{
	HttpWebRequest SendReq = HttpWebRequest.Create(Provider);
	HttpWebResponse GetRes = SendReq.GetResponse();

	System.IO.Stream StreamRes = GetRes.GetResponseStream;
	StreamReader ResStrmRdr = new StreamReader(ResStream, Encoding.UTF8);

	string IP = ResStrmRdr.ReadToEnd;

	StreamRes.Close();
	GetRes.Close();

	return IP;
}
Posted
Updated 22-Nov-20 3:08am
v2

C#
string IP = GetIP();

    public string  GetIP()
    {
        string Str = "";
        Str = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(Str);
        IPAddress[] addr = ipEntry.AddressList;
        return addr[addr.Length - 1].ToString();

    }
 
Share this answer
 
Comments
asmaa elbattanony 25-Jan-12 10:33am    
Thanx Kishorekke
Your Solution Worked like a charm ^_^

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