• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

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
0
njkelland
Asked:
njkelland
  • 6
  • 3
  • 2
  • +2
4 Solutions
 
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
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 6
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now