in

Microsoft Philippines Community

A community for users, customers, and partners of Microsoft products in the Philippines :)

How to Get IPAddress of a Browser, If the host is under ISA

Last post 07-24-2009 5:58 AM by vmaceda. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 11-27-2008 11:08 AM

    How to Get IPAddress of a Browser, If the host is under ISA

    I tried the following approach:

    using System;
    using System.Web;

    public partial class WhatsMyIP : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            tbIPs.Text += "HttpContext.Current.Request.UserHostAddress:" + Environment.NewLine +
                          HttpContext.Current.Request.UserHostAddress + Environment.NewLine + Environment.NewLine;
            tbIPs.Text += "HttpContext.Current.Request.ServerVariables['REMOTE_ADDR']:" + Environment.NewLine + HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] + Environment.NewLine;
            tbIPs.Text += "System.Net.Dns.GetHostName():" + Environment.NewLine + System.Net.Dns.GetHostName() + Environment.NewLine;
            tbIPs.Text += "System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString():" +
                          Environment.NewLine +
                          System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString() + Environment.NewLine;
        }
    }

    but it seems to failed, when test it on actual server which is under an ISA/Firewall.


    I have gone thru couple of forums such as:

    Possible solution, BUT we need to use Active X (which is not a good approach).
    Source: http://forums.asp.net/p/1276422/2432905.aspx#2432905

    Q: How can I use JS to detect client IP?
    A: You can get the actual IP by JavaScript, with the help of an ActiveX control, but the presents possibilities is low, because many browsers avoid ActiveX control and plug-in. see the source link for more details.

    Possible solution:
    See : http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21509072.html
    Q:
    Retrieving a clients IP address
    A: EugeneK-biruza: Anyway, reconfiguring the firewall to force it pass original address in additional headers will be the 100% working solution.

    Can someone point me on how to "reconfiguring the firewall to force it pass original address in additional headers" , where using ISA as firewall.

    Thanks in advanced.

    Many Thankz
    =Chris Aniano =
    skype: chrisaniano
    msn: chris.aniano@hotmail.com
    blog: http://ca-nobody.blogspot.com/
    running on => Ubuntu 9.04 Desktop


    Filed under: , ,
  • 11-27-2008 1:58 PM In reply to

    • jpaloma
    • Top 10 Contributor
      Male
    • Joined on 07-09-2004
    • Singapore
    • Posts 2,527
    • Points 25,652
    • MVP

    Re: How to Get IPAddress of a Browser, If the host is under ISA

    Hmm ... if one is able to do this across NAT, then that would invalidate NAT, right? Besides, what you will get would be private IP addresses, which are inaccessible in the Internet. I mean, imagine your results would be 192.168.x.x or 10.x.x.x, useless.

    Tama ba?

    Jay Paloma
    Security is a State of Mind
  • 11-27-2008 2:03 PM In reply to

    • cruizer
    • Top 10 Contributor
      Male
    • Joined on 07-20-2004
    • Singapore
    • Posts 9,384
    • Points 64,928
    • MVP

    Re: How to Get IPAddress of a Browser, If the host is under ISA

    I think if you pass thru ISA or other proxy servers it'll tack on a "X-Forwarded-For:" header which will contain the original IP of the browser that made the request. It's just a header though, and it can be forged so it isn't a very reliable means of identification.

    http://devpinoy.org/blogs/cruizer

    Naglalayong buksan at palayain ang kamalayan ng Pinoy .NET developer
  • 11-28-2008 3:50 PM In reply to

    Re: How to Get IPAddress of a Browser, If the host is under ISA

    Can someone help me on this, esp. on seting up the ISA server

    Many Thankz
    =Chris Aniano =
    skype: chrisaniano
    msn: chris.aniano@hotmail.com
    blog: http://ca-nobody.blogspot.com/
    running on => Ubuntu 9.04 Desktop


  • 12-18-2008 8:48 AM In reply to

    • pornstar
    • Top 10 Contributor
      Male
    • Joined on 10-04-2004
    • Antarctica
    • Posts 4,375
    • Points 39,144
    • MVP

    Re: How to Get IPAddress of a Browser, If the host is under ISA

    Have you tried this:

    public string IpAddress()
    {
        string strIpAddress;
        strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (strIpAddress == null)
        {
           strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
        }
        return strIpAddress;
    }

     

  • 07-20-2009 5:40 PM In reply to

    • labuji
    • Not Ranked
    • Joined on 07-19-2009
    • Posts 1
    • Points 18

    Re: How to Get IPAddress of a Browser, If the host is under ISA

    I did, it returns SERVER address, not the client.

  • 07-23-2009 12:22 PM In reply to

    Re: How to Get IPAddress of a Browser, If the host is under ISA

    dapat ang kunin mo e yung exposed IP (public IP), not the NAT IP. 

  • 07-23-2009 12:54 PM In reply to

    Re: How to Get IPAddress of a Browser, If the host is under ISA

    I encountered that problem before when I developed a web app using single singon and published outside. My concept is the web app get first the IP of the client machine, but we are behind ISA, in this case when user try to browse the web outside our network the result of the REMOTE_ADDR ip is the IP address of the ISA (according to our back office guys this is normal since are network is behind ISA). But when the IP is not equal to the IP addr of the ISA or the first 3 numbers is equal to our company ip (ex: 192.168.1.xx) then I am assuming that the user is on our network.

    Caezar P. Girang, MCP
    Consultant

    "Minsan sinabi ng pantas: Masama sa tao ang masyadong mahal ang sarili."





  • 07-24-2009 5:58 AM In reply to

    Re: How to Get IPAddress of a Browser, If the host is under ISA

    To make things complicated, things might turn out to be this...

    Company Internal Network (NAT) <-> (private)ISA(Public to ISP) <-> ISP Network (NAT) <-> (Private to ISP) Gateway (Public to the world)

     

Page 1 of 1 (9 items)
Copyright © 2008 Microsoft Philippines Community

Powered by Community Server (Commercial Edition), by Telligent Systems