Get client system ip address(visitor or user login ip)
i want to get client system ip address, i used some code but it is talking proxy ip address but i want to get client system ip address(User login ip address) pls help me, using asp.net c#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manoj BhoirRank #599 · 4K reputationPosted Jun 16, 2015, 4:19 AM EDT
Thirunavukkarsu j166 reputationPosted Jun 16, 2015, 4:24 AM EDT
Manoj BhoirRank #599 · 4K reputationPosted Jun 16, 2015, 4:37 AM EDT
/// method to get Client ip address
///
/// set to true if want to get local(LAN) Connected ip address
///
public static string GetVisitorIPAddress(bool GetLan = false)
{
string visitorIPAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (String.IsNullOrEmpty(visitorIPAddress))
visitorIPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
if (string.IsNullOrEmpty(visitorIPAddress))
visitorIPAddress = HttpContext.Current.Request.UserHostAddress;
if (string.IsNullOrEmpty(visitorIPAddress) || visitorIPAddress.Trim() == "::1")
{
GetLan = true;
visitorIPAddress = string.Empty;
}
if (GetLan && string.IsNullOrEmpty(visitorIPAddress))
{
//This is for Local(LAN) Connected ID Address
string stringHostName = Dns.GetHostName();
//Get Ip Host Entry
IPHostEntry ipHostEntries = Dns.GetHostEntry(stringHostName);
//Get Ip Address From The Ip Host Entry Address List
IPAddress[] arrIpAddress = ipHostEntries.AddressList;
try
{
visitorIPAddress = arrIpAddress[arrIpAddress.Length - 2].ToString();
}
catch
{
try
{
visitorIPAddress = arrIpAddress[0].ToString();
}
catch
{
try
{
arrIpAddress = Dns.GetHostAddresses(stringHostName);
visitorIPAddress = arrIpAddress[0].ToString();
}
catch
{
visitorIPAddress = "127.0.0.1";
}
}
}
}
return visitorIPAddress;
}
Saroj Kumar SahuRank #1,766 · 849 reputationPosted Jun 16, 2015, 4:45 AM EDT
UserHostAddressproperties on theRequestobject to get the client IP.Thirunavukkarsu j166 reputationPosted Jun 16, 2015, 10:22 PM EDT
Thirunavukkarsu j166 reputationPosted Jun 16, 2015, 10:27 PM EDT
Saroj Kumar SahuRank #1,766 · 849 reputationPosted Jun 16, 2015, 11:47 PM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted Jun 16, 2015, 11:54 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 17, 2015, 12:52 AM EDT
Thirunavukkarsu j166 reputationPosted Jun 17, 2015, 2:30 AM EDT
Saroj Kumar SahuRank #1,766 · 849 reputationPosted Jun 17, 2015, 8:43 PM EDT
Thirunavukkarsu j166 reputationPosted Jun 18, 2015, 2:59 AM EDT
Thirunavukkarsu j166 reputationPosted Jun 18, 2015, 2:59 AM EDT
RajaRank #1,035 · 1.9K reputationPosted Jun 10, 2018, 9:46 PM EDT
Sai Kumar KoonaRank #334 · 7.5K reputationPosted Sep 23, 2019, 2:14 AM EDT
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Sep 23, 2019, 3:03 AM EDT
You have used this code in you class.
Or refer below link
https://stackoverflow.com/questions/21155352/get-ip-address-of-client-machine
might you have help.
let me know if you have needed any other help.
Thanks
Rajender Gottipamula85 reputationPosted Sep 26, 2019, 1:14 AM EDT