如何将 IP 地址列表重定向到命令行功能?
我想查看哪些国家/地区正在尝试访问我的 VPS。我安装了一个名为“goiplookup”的工具,它是从另一个名为“geoiplookup”的项目中分叉出来的。如果我在命令行中输入:
goiplookup 8.8.8.8
它会返回:
US, United States
所以我想出了如何使用以下方法获取尝试访问我的服务器的 IP 列表:
sudo grep "disconnect" /var/log/auth.log | grep -v COMMAND | awk '{print $9}'
这给出了一个长长的 IP 列表,如下所示:
1.1.1.1
2.2.2.2
3.3.3.3
I无法弄清楚如何获取要由“goiplookup”工具处理的此 IP 列表。我尝试过这个:
sudo grep "disconnect" /var/log/auth.log | grep -v COMMAND | awk '{print $9}' | goiplookup
但这不起作用。我也尝试过但没有运气:
sudo grep "disconnect" /var/log/auth.log | grep -v COMMAND | awk '{print $9}' | xargs -0 goiplookup
I want to see what countries are trying to access my VPS. I have installed a tool called "goiplookup", which was forked from another effort called "geoiplookup". If I type this at the command line:
goiplookup 8.8.8.8
It returns this:
US, United States
So I figured out how to get a list of IPs that are trying to access my server by using this:
sudo grep "disconnect" /var/log/auth.log | grep -v COMMAND | awk '{print $9}'
Which gives a long list of IPs like this:
1.1.1.1
2.2.2.2
3.3.3.3
I cannot figure out how to get this list of IPs to be processed by the "goiplookup" tool. I tried this:
sudo grep "disconnect" /var/log/auth.log | grep -v COMMAND | awk '{print $9}' | goiplookup
but that did not work. I also tried with no luck:
sudo grep "disconnect" /var/log/auth.log | grep -v COMMAND | awk '{print $9}' | xargs -0 goiplookup
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
|排序| uniq
确保每个 IP 只出现一次xargs -n 1
以便每个找到的 IP 都由goiplookup
处理Try this:
| sort | uniq
to ensure each IP only appears oncexargs -n 1
so that each found IP is processes bygoiplookup
我会将其放入一个文件中,并创建一个小实用程序来解析它:
这将一次一行读取文件,并对每个 IP 执行 goiplookup。
I would put it into a file and make a small utility to parse it:
This will read through the file one line at a time and execute the goiplookup with each IP.
请注意,
geoiplookup
每次调用仅允许一个 IP。整个事情可以在 awk 中完成,但使用 grep 允许其余部分在无特权的情况下运行。
考虑一下
grep -w
(匹配整个单词)是否合适,在 awk 中你可以用!/(^|[^[:alnum:]_] 做类似的事情)命令($|[^[:alnum:]_])/
.Note that
geoiplookup
only allows one IP per invocation.The whole thing can be done in awk, but using grep allows the rest to be run unprivileged.
Consider whether
grep -w
(match whole word) is appropriate, and in awk you can do a similar thing with!/(^|[^[:alnum:]_])COMMAND($|[^[:alnum:]_])/
.我刚刚编写了一个 shell 脚本,可以运行。
I just made a shell script, which works.