确定请求是否来自本地网络(内联网) [英] Identify if request is coming from local network (intranet)

查看:32
本文介绍了确定请求是否来自本地网络(内联网)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用客户端或服务器端识别请求是来自 Internet 还是 Intranet.

I need to identify if a request comes from Internet or Intranet using either client-side or server-side.

我要解决的问题是:我们的网站可以从 Internet 和 Intranet 访问.Intranet 用户(公司内部用户)无法访问 Internet.我们使用的是 Google Anylitics,当内网用户访问该页面时,该页面需要很长时间才能上传,因为它试图下载从 Google 生成的 (ga) JavaScript 文件.

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.

有什么解决办法吗?

推荐答案

可以查看用户的ip地址.私有 ip4 地址始终以 10. 或 172. 或 192.* 开头...有关私有网络的更多信息 此处.

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.

您还可以制作 Google Analytics加载异步.

******************** 更新 - 请阅读 *************************************

***************** UPDATE - PLEASE READ *************************************

正如@igor-turman 正确指出的那样,只有172"和192"地址范围的一部分被指定为私人使用.其余以172和192开头的ip地址都是公开的.

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.

这是检查私有 IP 地址的正则表达式:

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])$)

您可以在 regexpal.com 此处上测试此正则表达式.

You can test this regex on regexpal.com here.

这篇关于确定请求是否来自本地网络(内联网)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆