Solved

IP address of client from MVC ASP.net application

Posted on 2013-12-03
3
1,062 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 82

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 82

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now