Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to get the Client Machine IP Address if Using Proxy

How to get the Client Machine IP Address if Using Proxy

Scheduled Pinned Locked Moved ASP.NET
tutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robymon
    wrote on last edited by
    #1

    How to get the Client Machine IP Address if Using Proxy and also not. I Tried the following code, but all the code is returning 127.0.0.1. 1) TextBox1.Text = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 2) if (Context.Request.ServerVariables["HTTP_VIA"] != null) // using proxy { TextBox1.Text = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP. } else// not using proxy or can't get the Client IP { TextBox1.Text = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); } 3) TextBox1.Text = HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]; 4) TextBox1.Text = HttpContext.Current.Request.UserHostAddress.ToString();

    R 1 Reply Last reply
    0
    • R Robymon

      How to get the Client Machine IP Address if Using Proxy and also not. I Tried the following code, but all the code is returning 127.0.0.1. 1) TextBox1.Text = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 2) if (Context.Request.ServerVariables["HTTP_VIA"] != null) // using proxy { TextBox1.Text = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP. } else// not using proxy or can't get the Client IP { TextBox1.Text = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); } 3) TextBox1.Text = HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]; 4) TextBox1.Text = HttpContext.Current.Request.UserHostAddress.ToString();

      R Offline
      R Offline
      Ravindra Bisen
      wrote on last edited by
      #2

      Hi dear, just try this using System.Net; and code : String strHostName, IPadd; strHostName = Dns.GetHostName(); IPAddress[] addr = Dns.GetHostAddresses(strHostName); IPadd = addr[0].ToString();

      R 1 Reply Last reply
      0
      • R Ravindra Bisen

        Hi dear, just try this using System.Net; and code : String strHostName, IPadd; strHostName = Dns.GetHostName(); IPAddress[] addr = Dns.GetHostAddresses(strHostName); IPadd = addr[0].ToString();

        R Offline
        R Offline
        Robymon
        wrote on last edited by
        #3

        This is showing the private IP of the Machine, not the actual IP.

        L 1 Reply Last reply
        0
        • R Robymon

          This is showing the private IP of the Machine, not the actual IP.

          L Offline
          L Offline
          logiclabz
          wrote on last edited by
          #4

          I think you are running this with http://localhost/... if upload in some live server System.Web.HttpContext.Current.Request.UserHostAddress should work... -------------------- logiclabz

          R 1 Reply Last reply
          0
          • L logiclabz

            I think you are running this with http://localhost/... if upload in some live server System.Web.HttpContext.Current.Request.UserHostAddress should work... -------------------- logiclabz

            R Offline
            R Offline
            Robymon
            wrote on last edited by
            #5

            OK. Now am running locally. i will try ...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups