How can I get the IP address of a visitor to my site?
The documentation I can find on RemoteAddress is pretty confusing.
I found one item on the web showing :
string ip=Request.ServerVariables("REMOTE_ADDR");
But I get errors with that. So I'm at a loss here.
TIA
Ken
Getting the remote IP address of a visitor to my site
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Roei BarRank #1,271 · 1.4K reputationPosted Sep 10, 2009, 10:06 AM EDT
Ken Barrett81 reputationPosted Sep 10, 2009, 10:01 AM EDT
String hostName = System.Net.Dns.GetHostName();
lblIpAdr.Text = hostName ;
Ken Kraska5 reputationPosted May 17, 2022, 10:59 AM EDT
Hi - The question asks "Getting the remote IP address of a visitor to my site" which is what I would like to do. However, the final working response shows -
String hostName = System.Net.Dns.GetHostName();
lblIpAdr.Text = hostName ;
which works for getting "hostname" , how do I get the "IP" address?
I am using MVC Core 5.0. when I try other solutions I can't seem to get them to work.
Thanks