-
Notifications
You must be signed in to change notification settings - Fork 6
限制 IP 访问指定路径 #20
Copy link
Copy link
Closed
Labels
Description
需求描述
部分页面只想让指定 IP 段的用户访问。
方案调研
调研过程
第三次研究
- Google:
IIS 限制访问 IP - 根据网上的资料,查到可以直接在 IIS 中只允许指定 IP 访问,但是!为子目录设置的 IP 访问限制不管用!禁止未指定的客户端访问之后,添加了允许的 IP 段,这些 IP 也无法访问,怎么设置都不行。
第二次研究
- Google:
validate ip:用于验证是否为合法的 IP 格式,关键字方向不对。 - Google:
check ip:检查 IP 是否在指定的 IP 段之类。 - danielcompton/ip-range-check
第一次研究
如何使 Express 只允许指定的 IP 段访问特定的路由?在下面的文章中给出了方法。
Express ip filter for specific routes?
入选方案
- danielcompton/ip-range-check:可以有效地限制访问者的 IP,可用于整个项目,也可应用于指定的路径,很方便。
排除方案
- IIS 的 IP 限制功能:无法让指定页面只允许部分 IP 访问。
应用过程
// 以 Express 为例
if (req.ip && req.ip.split(':').length > 0) {
const ip = req.ip.split(':').pop();
const isIpAllowed = ipRangeCheck(ip, config.allowedIpList);
if (isIpAllowed) {
// do something
} else {
res.sendStatus(404);
}
}要点总结
暂无。
Reactions are currently unavailable