Capture User's IP Address in an intranet app

I have built a .net app for our internal employees and I've implemented an audit log to track changes made via the app and I want to include the local IP of the machine at which the user is logged in. I've tried the methods below and both are returning the default gateway IP for the network, not the machine's local IP. Is there any way to get this info?

I've tried:
<%= Request.ServerVariables("REMOTE_HOST") %>
HttpContext.Current.Request.UserHostAddress
njkellandAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

samic400Commented:
This seems to work for me -

ipadd = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If ipadd = "" Then
  ipadd = Request.ServerVariables("REMOTE_ADDR")
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SriVaddadiCommented:
Try this

 Request.Servervariables("REMOTE_ADDR")
0
Todd GerbertIT ConsultantCommented:
With .Net, you should be able to use Request.UserHostAddress, you could also implement Windows security and track the user name instead of, or in addition to, the remote system's IP address.
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

njkellandAuthor Commented:
Thanks for the quick responses. So I tried the following and it's still returning the ip of the proxy server.

                //Get Host IP Address
                string ipadd = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (ipadd == "")
                {
                    ipadd = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                Session["HostIPAddr"] = ipadd;

Perhaps, is there a way to get the computer name instead? I just need some way to uniquely identify the location from where the user is logged in.
0
njkellandAuthor Commented:
Request.UserHostAddress also returns the proxy ip. I thought about implementing windows security but a few employees do access the site remotely (and for them i can log the ip just fine). I'd prefer to have one method for both internal and remote employees.
0
masterpassCommented:
0
njkellandAuthor Commented:
I'm still getting the proxy server's ip for any requests made within the network. Requests from outside are logging uniquely. At this point I've tried retrieving the variables "HTTP_VIA", "HTTP_X_FORWARDED_FOR", "HTTP_FORWARDED", "REMOTE_ADDR", and "LOCAL_ADDR". I even returned all the server variables as a string and read through them to see if there was anything I might be able to use and no luck. Apparently our proxy server is completely anonymizing our internal machines, which I guess is a security benefit but is making unique identification difficult. Any more suggestions on how I might be able to uniquely identify requests without relying solely on login credentials?
0
Todd GerbertIT ConsultantCommented:
It's possible the proxy is choosing not forward the client's IP information, or is using a different header.
Do you have any documentation for the proxy server?
I thought about implementing windows security but a few employees do access the site remotely  
You could still implement Windows security - your internal machines on the domain would log in transparently (assuming IE is set to do so), unbeknownst to the user, but your external users would simply need to provide a username & password.  You could also use the built-in .Net authentication system with a SQL database and have your system require a login.
0
Todd GerbertIT ConsultantCommented:
Try putting a test page in your project, and have it output the value of every request header, then just look for the one with the correct IP address, et voila!

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
	For Each var As String In Request.ServerVariables.AllKeys
		Response.Write(String.Format("{0}: {1}<br />{2}", var, Request.ServerVariables(var), vbCrLf))
	Next
End Sub

Open in new window

0
njkellandAuthor Commented:
thanks tberbert. i tried your suggestion and i still don't have any variable values that uniquely identify machines within the LAN. i'm going to talk to our net admin and see if he can provide me some documentatin on the proxy server.
0
njkellandAuthor Commented:
thank you to everyone who took time to respond. i've got it all solved. it turns out it was a dns setup issue. i didn't realize how our net admin had this set up so it was always resolving to ip of our network firewall. once i setup the dns for the site to point to my dev server ip everything started working like a charm!! thanks for all the feedback.
0
njkellandAuthor Commented:
Everyone's answer was technically right so I just distributed the points. My original solution worked fine once I got the seperate dns issue resolved. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.