这个 Squid 正则表达式过滤规则如何工作?
在我们的 Squid 服务器上,管理员设置了一个新的正则表达式规则:
^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+
我知道它代表 IP 地址,但它允许所有 URL 通过,仅 ping 外部地址已停止。 UltraSurf 等隧道软件也已停止连接到服务器。 Skype 也无法连接。
请解释一下这是如何工作的! 谢谢。
On our Squid server, the admin has put on a new regex rule:
^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+
I know that it stands for IP address, but it allows all URLs to go through, only pinging external address has stopped. Also tunneling software like UltraSurf have stopped connecting to the server. Skype also is not getting connected.
Please explain how this works! Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您对 Squid 服务器的具体问题,但正则表达式的作用如下:
[0-9]+
表示“任何数字一次或多次”,因此它匹配一个字符串以数字开头一次或多次,后跟一个点,后跟一次或多次数字,后跟一个点,后跟一次或多次数字,后跟点,后跟一次或多次数字..然后还有其他什么。 本质上,它匹配任何 IP 地址,因此不会过滤掉任何内容。 它还会匹配甚至不是有效 IP 地址的内容,例如123456.123456.123456.123456
或1.1.1.1
或125.252.252.252asdf
。I am not sure about your particular issue with the Squid server, but here is what the regex does:
[0-9]+
means "any digit one or more times", so it is matching a string that begins with a digit one or more times, followed by a dot, followed by a digit one or more times, followed by a dot, followed by a digit one or more times, followed by dot, followed by a digit one or more times.. then anything else. In essence, it is matching any IP address, so it wouldn't filter anything out. It will also match things that are not even valid IP addresses like123456.123456.123456.123456
or1.1.1.1
or125.252.252.252asdf
.Paolo 很好地解释了正则表达式的含义! 如前所述,当前使用的正则表达式太弱(或者我应该说限制性太强!)
如果您想要一个更好的正则表达式来匹配 IP 地址,请参阅 此页面。
Paolo has explained the meaning of the Regex well! As mentioned, the Regex currently being used is too weak (or should I say too restrictive!)
If you want a much better Regex to match IP addresses, see this page.