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

Here is code to get the IP Address For User Tracking

Discussion in 'Visual Basic .NET' started by digitalpower, Dec 20, 2008.

  1. digitalpower

    digitalpower BANNED BANNED

    Joined:
    Dec 16, 2008
    Messages:
    303
    Likes Received:
    69
    In case you want to do some simple user tracking on your ASP.NET website, you can use this function to get the current user's IP address.

    Code:
    Public Shared Function GetIPAddress() As String
            Dim sIPAddress As String
            sIPAddress = HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR")
            If sIPAddress = "" Then
                sIPAddress = HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
            End If
            Return sIPAddress
        End Function
     
    • Thanks Thanks x 1
  2. aahx489

    aahx489 Newbie

    Joined:
    Jan 28, 2009
    Messages:
    2
    Likes Received:
    0
    Public Shared Function GimmeClientIP() as String
    Return Request.UserHostAddress
    End Function



    Note: The Request.UserHostAddress return's the Client's IP. Works all the time for me :) :) :)
     
  3. crashed

    crashed Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 13, 2008
    Messages:
    958
    Likes Received:
    1,198
    Occupation:
    Guru-slayer
    Location:
    Behind the VPN...
    Home Page:
    The code by digitialpower gets the users real IP even if they are behind a proxy, your's will just get the proxy address:)

    Nice going dp :)
     
  4. loading...

    loading... Registered Member

    Joined:
    Apr 11, 2012
    Messages:
    84
    Likes Received:
    27
    Can I use it with my wordpress blog? or is there any solution for wordpress (php/html)?
     
  5. BlueZero

    BlueZero Power Member

    Joined:
    Jul 6, 2011
    Messages:
    500
    Likes Received:
    257
    Occupation:
    Webdeveloper, Project Manager
    Location:
    Byte in the Net
    Home Page:
    here you have a php code for it.

    PHP:
    if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '')
            { 
            
    $sIP $_SERVER['HTTP_X_FORWARDED_FOR']; 
            
    $sProxy $_SERVER['REMOTE_ADDR']; 
            
    $sHost = @gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']); 
            }
            elseif ( isset( 
    $_SERVER['REMOTE_ADDR'] ) )
            { 
            
    $sIP $_SERVER['REMOTE_ADDR']; 
            
    $sHost = @gethostbyaddr($_SERVER['REMOTE_ADDR']); 
            }