HOW TO GET CLIENT IP ADDRESS

Kenny Tangnde

Total Post:68

Points:476
Posted by  Kenny Tangnde
C# 
C#
 2117  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. Mark Toy

    Post:7

    Points:49
    Re: How to get client IP address

    Why you want to get client IP address?

  1. Kenny Tangnde

    Post:68

    Points:476
    Re: How to get client IP address

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

  1. Awadhendra Tiwari

    Post:126

    Points:882
    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. Kenny Tangnde

    Post:68

    Points:476
    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);
            }
        }
    }

  1. Kenny Tangnde

    Post:68

    Points:476
    Re: How to get client IP address

    Hi Awadhendra Tiwari,

    How get the local computer name.

    Thanks.

  1. Awadhendra Tiwari

    Post:126

    Points:882
    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. Kenny Tangnde

    Post:68

    Points:476
    Re: How to get client IP address

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!