locked
Accessing web url from internet or intranet RRS feed

  • Question

  • User-1254072439 posted

    How do i check if user is accessing web url from internet (outside the office network) or without internet (LAN-inside office network ).

    Tuesday, April 3, 2018 5:22 AM

All replies

  • User-369506445 posted

    hi

    please try below code

    public bool CheckClientIsOnLAN()
            {
                string ipString = System.Web.HttpContext.Current.Request.UserHostAddress;
                byte[] ipBytes = System.Net.IPAddress.Parse(ipString).GetAddressBytes();
                int ip = System.BitConverter.ToInt32(ipBytes, 0);
    
                // your network ip range
                string ipStringFrom = "192.168.1.0";
                byte[] ipBytesFrom = System.Net.IPAddress.Parse(ipStringFrom).GetAddressBytes();
                int ipFrom = System.BitConverter.ToInt32(ipBytesFrom, 0);
    
                string ipStringTo = "192.168.1.255";
                byte[] ipBytesTo = System.Net.IPAddress.Parse(ipStringTo).GetAddressBytes();
                int ipTo = System.BitConverter.ToInt32(ipBytesFrom, 0);
    
                bool clientIsOnLAN = ipFrom >= ip && ip <= ipTo;
    
                return clientIsOnLAN;
            }

    if your request be local return true otherwise return false

    Tuesday, April 3, 2018 8:05 AM
  • User-1254072439 posted

    Thanks for your reply, is there anyway without checking IP address

    Tuesday, April 3, 2018 9:39 AM
  • User-369506445 posted

    what is you problem with IP address . Eventually, all address spaces are converted to IP address

    Tuesday, April 3, 2018 9:52 AM