Solved

IP address of client from MVC ASP.net application

Posted on 2013-12-03
3
1,072 Views
Last Modified: 2013-12-08
What is the best foolproof way of getting client IP address for the client who is behind firewall, proxy or load balancer in ASP.net to harden the security of the site?
0
Comment
Question by:Jugnoo2013
  • 2
3 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39693324
If this is on the public internet, the only thing you can get is their public IP address.  It's reported in the server variables under REMOTE_ADDR.

This simple program reports all the server variables available on your server.  REMOTE_ADDR is added separately at the bottom.
<%@ Page Language = "VBScript" AspCompat="True" %>
<% Response.Buffer = true %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>ASPX .NET Server Variables</title>
</head>
<body>
<h1 align="center">ASPX .NET Server Variables</h1>
<%
Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection

' Load ServerVariable collection into NameValueCollection object.
coll=Request.ServerVariables 
' Get names of all keys into a string array.
arr1 = coll.AllKeys 
For loop1 = 0 To arr1.GetUpperBound(0)
   Response.Write("<b>" & arr1(loop1) & "</b>: ")
   arr2 = coll.GetValues(loop1) ' Get all values under this key.
   For loop2 = 0 To arr2.GetUpperBound(0)
      Response.Write("Value " & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)) & "<br>")
   Next loop2
Next loop1

Response.Write ("<br>" & vbCrLf)
Response.Write ("REMOTE_ADDR" & ": " _
	& Request.ServerVariables("REMOTE_ADDR") _
	& "<br>" & vbCrLf)

%>

</body>
</html>

Open in new window

0
 

Author Comment

by:Jugnoo2013
ID: 39693357
Thanks, I will take a look. Does same hold true for intranet sites?
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39693399
Intranet clients will show their intranet IPs as long as there is no proxy in between you and them.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question