Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi experts.
i want c# code for to get client system ip address. i used this code
C#
public string GetIpAddress()
{
  string stringIpAddress;
  stringIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (stringIpAddress == null)
{
  stringIpAddress = Request.ServerVariables["REMOTE_ADDR"];
}
  return "Visitor IP Address is "+stringIpAddress;
}


using this code i get answer as " ::1 ".. i don't want this.. i want system ipv4 address.

please help me



Thanks in Advance....
Posted

1 solution

Hello



using System.Net;

Private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();

IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);

IPAddress[] addr = ipEntry.AddressList;

return addr[addr.Length-1].ToString();

}




Thanks,
Abhimanyu Rawat
 
Share this answer
 

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