Click here to Skip to main content
16,020,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried with all google search logics but there is no exact solution
getting different ip addresses
How to get exact ip address like which is displyed in ipcofig ip4 ip address in client machine or user logged in machine


host ip address ex: 123:23:0;

user 1 ip address ex: 23:45;
user 2 ip address ex : 43:56;

i want same user ip addresses like 23:45 , 43:56 that should be display in ipconfig /all ipaddresses if we check

What I have tried:

I have tried but getting different ip address.

C#
string clientIPAddress = string.Empty;
            try
            {
                if (null == HttpContext.Current || null == HttpContext.Current.Request)
                    return null;

               
                var request = HttpContext.Current.Request;
                var forwards = request.Headers.Get("X-Forwarded-For");
                if (!string.IsNullOrEmpty(forwards))
                {
                    var values = forwards.Split(HEADER_SEPARATOR, 2);
                    return values[0];
                }

                /*else*/
                clientIPAddress=  request.UserHostAddress;
            }
Posted
Updated 24-Mar-18 4:57am
v2
Comments
Patrice T 24-Mar-18 10:33am    
What do you want to do with this ip address?
PIEBALDconsult 24-Mar-18 10:35am    
If DHCP is involved, the IP address will likely change, so what good is it?

1 solution

Quote:
How to get exact ip address like which is displyed in ipcofig ip4 ip address in client machine or user logged in machine

For what usage ?
Since your client is likely to be in a company or home network with a non routable address like 192.168.0.xxx, that address will not be unique.
Quote:
host ip address ex: 123:23:0;

An ip address is 4 parts, not 3.
Quote:
user 1 ip address ex: 23:45;
user 2 ip address ex : 43:56;

User ip addresses are not related to host address.

The trick is that host have 2 ip addresses.
1 ip address is the public address, the one you see, the second is for company or home network only, it is not seen from outside.
 
Share this answer
 
Comments
DGKumar 26-Mar-18 14:10pm    
Hi,
I need to maintain logs for my website that should be get userid and from which network ip address he has logged in my website.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900