具有正则表达式 url 匹配的 iptables

问题描述 投票:0回答:2

我需要实现什么 我需要计算有多少用户打开正确的网站和子网站 例如`http://stackoverflow.com' 'https://stackoverflow.com/questions'

我有什么 Centos 7 上的路由器设置 iptables https://github.com/xnsystems/kpcre/wiki/iptables-string-regex

我不能用鱿鱼。 此计数系统无法更改 IP 标头(源 IP 地址和目标 IP 地址) 这就是为什么我需要 count 使用带有 log 选项的 iptables 或者也许有软件可以在不修改数据包的情况下计算 url

问题 我找不到一种方法来查看有多少 IP 地址(有多少用户)点击了正确的 url

我的 iptables 行看起来像这样,但不起作用 我的意思是匹配所有网址(以及所有子网址),不仅是http://stackoverflow.com

sudo iptables -I OUTPUT -p tcp --dport 80 -m string --string "^http://stackoverflow.com$" --algo regex -j ACCEPT

请帮我处理这个案子。

更新:
下面三个例子请尝试让它们起作用

sudo iptables -I OUTPUT -p tcp --dport 80 -m string --string stackoverflow.com --algo regex -j ACCEPT  
sudo iptables -I OUTPUT -p tcp --dport 80 -m string --string stackoverflow.com/documentation --algo regex -j ACCEPT  
sudo iptables -I OUTPUT -p tcp --dport 80 -m string --string stackoverflow.com/questions'; --algo regex -j ACCEPT  

如你所见,我使用了 --algo regex。
如果您知道没有它的其他解决方案,请提出建议。

regex iptables
2个回答
0
投票

我检查了规范链接,它不是很完整(例如

\b
似乎知道,但没有解释),但我认为你需要的正则表达式是:

^(http:\/\/){0,1}[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+(\/[a-zA-Z0-9_-]+){0,}$

更新:允许

http://
前缀和
/documentation
后缀。

请尝试一下。
未指定捕获组

()
的使用,但这通常是有效的。
如果您给出匹配和不应该匹配或不匹配和应该匹配的示例,我将调整这个答案。 最简单的调整是在
[a-zA-Z0-9_
-]
之间的两个位置插入更多字符(允许用于 URL)。


0
投票

数据包中包含 URL 的行不仅包含 URL,而且还包含一些额外的关键字。

如果您想仅阻止“http://stackoverflow.com”,那么您应该像这样指定 URL: iptables -I OUTPUT -p tcp --dport 80 -m string --string "/\/ .+Host: stackoverflow.com/si" --algo regex -j DROP

或者如果您想仅阻止“
http://stackoverflow.com/questions

”,那么您应该像这样指定 URL: iptables -I OUTPUT -p tcp --dport 80 -m string --string "/\/questions .+Host: stackoverflow.com/si" --algo regex -j DROP

© www.soinside.com 2019 - 2024. All rights reserved.