I need to identify if a request comes from Internet or Intranet using either client-side or server-side.
The problem I'm trying to solve is: our web site can be accessed from internet and intranet. The intranet user (user inside company), does not have access to internet. We are using Google Anylitics, when intranet user access the page, the page take so long to upload because it tries to download (ga) JavaScript file generated from Google.
Any solution?
You can check the ip address of a user. Private ip4 address always start with either 10., or 172., or 192.* ... more info on private networks here.
You can also make Google Analytics load Asynchronous.
***************** UPDATE - PLEASE READ *************************************
As @igor-turman has correctly pointed out, that only a portion of the "172" and the "192" address ranges are designated for private use. The remaining ip addresses starting with 172 and 192 ARE PUBLIC.
Here is the regex expression to check for private IP addresses:
(^192\.168\.([0-9]|[0-9][0-9]|[0-2][0-5][0-5])\.([0-9]|[0-9][0-9]|[0-2][0-5][0-5])$)|(^172\.([1][6-9]|[2][0-9]|[3][0-1])\.([0-9]|[0-9][0-9]|[0-2][0-5][0-5])\.([0-9]|[0-9][0-9]|[0-2][0-5][0-5])$)|(^10\.([0-9]|[0-9][0-9]|[0-2][0-5][0-5])\.([0-9]|[0-9][0-9]|[0-2][0-5][0-5])\.([0-9]|[0-9][0-9]|[0-2][0-5][0-5])$)
You can test this regex on regexpal.com here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With