Get users IP address

Rate It (5)

Last post 12-19-2009 1:27 PM by jamalqudah. 58 replies.

Sort Posts:

  • Re: Get users IP address

    11-14-2008, 9:26 AM
    Locked
    • All-Star
      65,332 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,708
    • TrustedFriends-MVPs

     I will write you some code for you, once I clarify what you require. You cited Q1111.xxxxx.xx.xx.xx

    IP addresses have four components, but you show 5.

    However you may like to go to http://www.codeplex.com/IPAddressExtensions and try the IP Extensions project.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
    See the FAQ on the correct forum to post at, at http://forums.asp.net/p/1337412/2699239.aspx#2699239
  • Re: Get users IP address

    11-14-2008, 9:33 AM
    Locked
    • Member
      9 point Member
    • Mick Breen
    • Member since 10-09-2008, 2:43 PM
    • Northern Ireland
    • Posts 39

    Thanks for the post.

    This didn't work anymore ideas?

    Mick

  • Re: Get users IP address

    11-14-2008, 9:37 AM
    Locked
    • Member
      9 point Member
    • Mick Breen
    • Member since 10-09-2008, 2:43 PM
    • Northern Ireland
    • Posts 39

    This is not the IP Address but the computer name Q1111.

    The rest of the xxxx.xxx.xx is the environment.

    Mick

  • Re: Get users IP address

    11-14-2008, 9:58 AM
    Locked
    • All-Star
      65,332 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,708
    • TrustedFriends-MVPs

     Here is the function plus some unit test code


    #region " Copyleft "
    // Copyright (C) 2008 Clive Chinery
    //
    // This library is free software; you can redistribute it and/or
    // modify it under the terms of the GNU Lesser General Public
    // License as published by the Free Software Foundation; either
    // version 2.1 of the License, or (at your option) any later version.
    //
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    // Lesser General Public License for more details.
    //
    // You should have received a copy of the GNU Lesser General Public
    // License along with this library; if not, write to the Free Software
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    #endregion

    namespace Demo
    {
      using System;
      using NUnit.Framework;

      /// <summary>
      /// IpAddressTest
      /// </summary>
      [TestFixture]
      public class IpAddressTest
      {
        /// <summary>
        /// Test GetBlock1
        /// </summary>
        [Test]
        public void GetBlock1Test1()
        {
          Assert.AreEqual("123", GetBlock1("123.111.222.103"));
        }
        /// <summary>
        /// Test GetBlock1 
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void GetBlock1Test2()
        {
          Assert.AreEqual("123", GetBlock1("123.111.222"));
        }
        /// <summary>
        /// Get Block 1
        /// </summary>
        /// <param name="input">IP Address</param>
        /// <returns>Block 1</returns>
        public string GetBlock1(string input)
        {
          var work = (string.Empty + input).Split('.');
          if (work.Length != 4)
          {
            throw new ArgumentException("input is not in form xxx.xxx.xxx.xxx");
          }
          return work[0];
        }
      }
    }

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
    See the FAQ on the correct forum to post at, at http://forums.asp.net/p/1337412/2699239.aspx#2699239
  • Re: Get users IP address

    01-20-2009, 4:53 AM
    Locked
    • Member
      191 point Member
    • svibuk
    • Member since 10-16-2008, 10:22 AM
    • Posts 782

    i am using Dim IPAddress IPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If IPAddress = "" Then IPAddress = Request.ServerVariables("REMOTE_ADDR") End If but i am getting 127.0.0.1 i suppose i am getting it due to my local host

    based on this ip i need to find the country of that IP using vb.net or javascript. how ca i achieve it

     

    hope to get help

    Filed under: ,
  • Re: Get users IP address

    01-20-2009, 9:56 AM
    Locked
    • All-Star
      65,332 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,708
    • TrustedFriends-MVPs

     >based on this ip i need to find the country of that IP using vb.net or javascript. how ca i achieve it

    Getting Country from IP address is somewhat problematical. For example whist I have been in the United Kingdom, I have been told that I am in Germany one and in America at another time.

    Code for Address look up

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
    See the FAQ on the correct forum to post at, at http://forums.asp.net/p/1337412/2699239.aspx#2699239
  • Re: Get users IP address

    01-22-2009, 9:58 AM
    Locked
    • Member
      6 point Member
    • villandro
    • Member since 01-22-2009, 2:55 PM
    • Posts 3

    l

  • Re: Get users IP address

    01-22-2009, 10:04 AM
    Locked
    • Member
      6 point Member
    • villandro
    • Member since 01-22-2009, 2:55 PM
    • Posts 3

    Dim clientIP as String = Request.UserHostAddress.ToString

    lblShowIp.Text = clientIP

  • Get users IP address

    01-28-2009, 5:14 AM
    Locked
    • Contributor
      5,048 point Contributor
    • yrb.yogi
    • Member since 01-06-2009, 11:44 AM
    • Ahmedabad
    • Posts 853

    Get Users IP address...???

    but How???

    can u expalin me????

    Yogesh Bhadauriya
    ------------------------
    Who Care! Who Regret!
    ( .Net All About )

  • Re: Get users IP address

    01-28-2009, 5:32 AM
    Locked
    • All-Star
      60,913 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 10:28 AM
    • Mumbai, India
    • Posts 10,698
    • TrustedFriends-MVPs

    yrb.yogi:

    Get Users IP address...???

    but How???

    can u expalin me????

    http://forums.asp.net/p/1360555/2807643.aspx#2807643

    MAK [MVP ASP/ASP.Net]

    ASP.Net Freelancer/Consultant My Site : ASPSnippets

    Calling ServerSide methods using JavaScript

    GridView: Excel like AutoFilter Feature
  • Re: Get users IP address

    01-28-2009, 5:40 AM
    Locked
    • All-Star
      65,332 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,708
    • TrustedFriends-MVPs

     You can get the user's IP Address by:

        var useraddress = Request.UserHostAddress;

    For details, see:

     

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
    See the FAQ on the correct forum to post at, at http://forums.asp.net/p/1337412/2699239.aspx#2699239
  • Re: Get users IP address

    01-28-2009, 5:45 AM
    Locked
    • All-Star
      65,332 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,708
    • TrustedFriends-MVPs

     Or more fully using the function I gave earlier.

        var useraddress = Request.UserHostAddress;
        var test = IPAddress.Parse(useraddress);
        var result = CommonData.IPAddressToBytes(test);
        lblOutput.Text = result[0] + "." + result[1] + "." + result[2] + "." + result[3]; 

    This displays (not surpringly)  127.0.0.1

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
    See the FAQ on the correct forum to post at, at http://forums.asp.net/p/1337412/2699239.aspx#2699239
  • Re: Get users IP address

    02-11-2009, 8:31 PM
    Locked
    • Member
      2 point Member
    • Bonner
    • Member since 02-12-2009, 1:28 AM
    • Posts 1

     I think this is what you were looking for :

    <% Response.Write Request.ServerVariables("REMOTE_ADDR") %>
     

    Hope it helps :)

    Bonner,
    IP Address
  • Re: Get users IP address

    05-02-2009, 2:58 AM
    Locked
    • Member
      2 point Member
    • sunnyhasan
    • Member since 12-30-2006, 8:28 AM
    • US
    • Posts 2

     string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();

    Is the uppoer statement  returning the client ip address? That is a hexcode. But IP address should not be in that format right?

    string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(1).ToString(); I have used this GetValue(1) instead GetValue(0).

    Is that ok? Can you please explain that? I need to log all the ip address of the users when they visit a specific website...please help me.

    Thanks.

    -http://sunnyhasan.blogspot.com

    http://sunnyhasan.blogspot.com
    Filed under: ,
  • Re: Get users IP address

    05-02-2009, 5:39 AM
    Locked
    • All-Star
      65,332 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,708
    • TrustedFriends-MVPs

     Try

          var ipAddress = Request.UserHostAddress.ToString();

    or if using an earlier version of the framework

          string ipAddress = Request.UserHostAddress.ToString();

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
    See the FAQ on the correct forum to post at, at http://forums.asp.net/p/1337412/2699239.aspx#2699239
Page 3 of 4 (59 items) < Previous 1 2 3 4 Next >