在 Web 分析工具(perl 或 sed)的输出中使 IP 匿名?
我使用 http://www.w3perl.com/ 分析了日志,现在我希望 IP 匿名。
所以我希望它们在整个目录中的所有 html 文件中进行更改。
我考虑过将所有 IP 的第三个和第四个八位字节始终转换为相同的数字。但我读到了一些关于对它们进行异或运算的内容 - 那是关于什么的?
管理更换的更好方法是什么?为什么? sed 或 perl 或其他选项?
我对此很陌生,我希望我对其他主题进行了足够的搜索。我还没有找到任何与我的问题相关的内容。 预先感谢,请原谅我的英语。 这个网站太棒了——过去几天我学到了很多东西!
I analysed logs with http://www.w3perl.com/, now i want the IPs made anonymous.
So i want them changed in all html-files in the whole directory.
I thought about just always turning the third and fourth octet into the same number for all IPs. But i read something about XOR-ing them - what is that about?
what is the better way to manage the replacing and why? sed or perl or another option?
I am pretty new to this, i hope i searched the other topics enough. I haven't found anything related to my problem.
Thanks in advance and please excuse my English.
This website is just great - i've learned so much in the last days!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
perl
可以更好地实现 IP 地址屏蔽。您可以在此处查看如何使用已有的模块,这样您就不必重新发明轮子。不幸的是我不懂perl
,所以我只能提供sed
解决方案。您可以使用类似的方法来替换文件中的所有 IP 地址。
您的文件:
第 1 步:识别 IP 地址:
第 2 步:用您的掩码替换 IP 地址
您可以使用
sed -i
(内联) 替换或使用>
将输出重定向到另一个文件。显然,这可以简化为以下内容。上面的内容对于调试很有用,因为您可以在进行更改之前查看正在更改的内容。
祝你好运!!
更新:
正如Mark在
评论
中发布的那样,perl
变体将是 -更新 II:
根据OP的要求,以下一行将找到文件并执行替换。
Masking IP-Address can be better achieved with
perl
. You can take a look here for using already available modules so that you won't have to re-invent the wheel. Unfortunately I don't knowperl
, so I can only offersed
solution.You can use something like this for replacing all ip-address in your file.
Your file:
Step 1: Identify IP-Addresses:
Step 2: Replace IP-Address with your mask
You can either make
sed -i
(in-line) substitution or use>
to re-direct your output to another file.Obviously this can be reduced to the following. The above would be useful for debugging as you can view what is being changed before making the change.
Good Luck!!
Update:
As posted by Mark in the
comments
, aperl
variant would be -Update II:
As requested by OP, the following one-liner will find the files and perform the substitution.