1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to retrieve the TRUE IP address in ASP

Discussion in 'ASP' started by pradeep, May 1, 2005.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Request.ServerVariables("REMOTE_ADDR") can be used to retrieve the IP address of the client machine.

    While clients connect internet via a proxy server, the above method only return the IP address of the proxy server, other than the REAL IP address of the client machine. In order to request the TRUE IP address of the client via the proxy server, you may use
    Request.ServerVariables("HTTP_X_FORWARDED_FOR").

    One more thing, if the client does not connect the internet via a proxy server, then Request.ServerVariables ("HTTP_X_FORWARDED_FOR") will return a null value. Therefore, you can use this method in your program like this:

    Code:
    userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR") 
    If userip = "" Then 
       userip = Request.ServerVariables("REMOTE_ADDR")
    End if
     
    i.e. If client connect the internet via a proxy server, we take the value returned by

    HTTP_X_FORWARDED_FOR, otherwise we take the value returned by REMOTE_ADDR
     
    zhangao0086 likes this.
  2. raju123

    raju123 New Member

    Joined:
    Oct 28, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
  3. raju123

    raju123 New Member

    Joined:
    Oct 28, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    is any problem in Request.UserHostAddress.ToString()
     
  4. sudamerica

    sudamerica New Member

    Joined:
    Sep 19, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hi sorry iam new, where should i put all that?
    thanks a lot
     
  5. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    What's your objective?
     
  6. urstop

    urstop New Member

    Joined:
    Oct 17, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Thats a good point. If it is going to retreive the original IP, why do people use all these proxy sites to hide their traces? So, if we are going to use the SERVER VARIABLE specified by you, we will be knowing there true IPs, isin't it? Or is there a different way these proxy sites work?
     
  7. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    There are two types of proxies transparent and anonymous, transparent server sends over the original IP, where anonymous hides the original IP, the above code will only work for a transparent proxy!
     
  8. urstop

    urstop New Member

    Joined:
    Oct 17, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Ok thanks, that clears up things. As a suggestion, it would be good to add this info about transparent and anonymous proxies in your original message.
     
  9. dilipv

    dilipv New Member

    Joined:
    Feb 7, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi pradeep,

    Can you help me to suggest how to use anonymous proxies. how to implement such proxies in asp.net application.

    Thanks in advance.

    Jitesh
    programmer
     
  10. gkumar

    gkumar New Member

    Joined:
    Jun 16, 2009
    Messages:
    58
    Likes Received:
    5
    Trophy Points:
    0
    This tutorial covers on fetching the exact client IP address. Here the author explains that using Request.ServerVariables("REMOTE_ADDR") can only bring the IP address of the proxy server. So the author finally decided to use...
     
  11. omiban

    omiban New Member

    Joined:
    Jun 28, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    This tutorial covers on fetching the exact client IP address. Here the author explains that using Request.ServerVariables("REMOTE_ADDR") can only bring the IP address of the proxy server. So the author finally decided to use Request.ServerVariable("HTTP_X_FORWARDED_FOR") to collect the true IP addresses of the client server.
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Where is the tutorial?
     
  13. evolu

    evolu New Member

    Joined:
    Jul 3, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hi i have a two type of sites say internet and intranet site can i redirect the user based on their connectivity? if so how can i do so both the web site are there in same server
     
  14. Manojbijnori

    Manojbijnori New Member

    Joined:
    Jun 16, 2009
    Messages:
    29
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Lecturer In Computer Science Department In Enginer
    Location:
    Bijnore
    this code is in working condition or not.please explain the procedure in detail how to retrieve tehe true Ip address and mail me my email id is manojbijnori12@gmail.com:snobby:

     

Share This Page