0

I have a .net mvc application deployed on my server. The application requires authentication of user based on his location, i.e, user should be allowed to login to the application only if he is accessing it from a network with gateway say '192.168.x.y' and not from any other network. When I try to get the gateway address in the application, I am always getting the gateway of the server in which my application is deployed. How can I get the gateway address of the system from which the user is trying to access the application?

This is what I used

            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
                GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses;
                if (addresses.Count > 0)
                {
                    return addresses[0].Address.ToString();
                }
            }
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Does this answer your question? [How to get a user's client IP address in ASP.NET?](https://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net) – Jeremy Thompson Jul 01 '20 at 07:17
  • This helps me to get the client ip. But I want to get the gateway address, so that user can login to all systems in a particular branch. – Nejma Latheef Jul 02 '20 at 06:29
  • **How can I get the gateway address of the system from which the user is trying to access the application** - that's why I referred you to that link where they explain it's not possible. – Jeremy Thompson Jul 02 '20 at 07:37

0 Answers0