How to get client IP address

Total Post:68

Points:476

C# 
C#
 2670  View(s)
Ratings:
Rate this:

Hi all,

How to get client IP address,And will IP address stored in the database

thanks in advance.

  1. Re: How to get client IP address

    Why you want to get client IP address?

  1. Re: How to get client IP address

    for security,
    Consider the user's account unusual, such as remote login

  1. Re: How to get client IP address

    Hi Aken,

    If you want to know client ip address in asp.net then you can use following code
    Request.UserHostAddress()   ---> It will give you client address

    And if you want it in c# then you can write following code
       
    IPAddress[] addresses = Dns.GetHostByName( "MACHINE1" ).AddressList;

    foreach( IPAddress address in addresses )
    {
        Console.WriteLine( address.ToString() );
    }

    Thanks.

  1. Re: How to get client IP address

    Hi Awadhendra Tiwari,

     thanks for your helping.

    using System.Net;
    namespace GetClientIPAddress
    {
        class Program
        {
            static void Main(string[] args)
            {
                //GetHostByName(this parameter  is what).
            IPAddress[] addresses = Dns.GetHostByName("").AddressList; //If only want IP. How to do that?
           Console.Write("Your IP Address is:");
                foreach (IPAddress address in addresses)
                {
                    Console.WriteLine(address.ToString());
                }
                Console.ReadKey(true);
            }
        }
    }

      Modified On Mar-29-2018 04:30:28 AM
  1. Re: How to get client IP address

    Hi Awadhendra Tiwari,

    How get the local computer name.

    Thanks.

  1. Re: How to get client IP address

    Hi...
    You can use following line of code to get machine name.

    Console.WriteLine(Environment.MachineName);

    Thanks.

  1. Re: How to get client IP address

    Hi Awadhendra Tiwari,
    My problem has been solved, thank you for your help.

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.