linux - bash IP whois 查找脚本

标签 linux bash shell whois

我有一个不错的管理脚本,用于检查哪些 IP 正在登录 Web 应用程序,但我需要在开始时使用 whois 让它更漂亮,然后我想到了 geoip。

目前我已经解决了其中的 whois 部分 - 我的问题是因为有多个 IP - whois 不知道如何处理它们

有什么好的想法吗?还有关于 geoips 的想法会很可爱!

干杯

#!/bin/bash

#Setting date and time (y and z aren't being used at the moment)
x="$(date +'%d/%b/%Y')"
y="$(date +'%T')"
z="$(date +'%T' | awk 'BEGIN { FS =":"} ; {print $1}')"

#Human readable for email title
emaildate=$(date +"%d%b%Y--Hour--%H")

#Setting date and time for grep and filename
beta="$(date +'%d/%b/%Y:%H')"
sigma="$(date +'%d-%b-%Y-%H')"

#Current SSL Access logs
log='/var/log/apache2/ssl_access.log'
#Set saved log location
newlogs=/home/user/Scripts/logs

grep user@user.com $log | grep $beta | awk 'BEGIN { FS = " " } ; { print $1 }' | sort -u >> $newlogs/adminusage"$sigma".txt

#Preform whois
#whoip=`grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' $newlogs/adminusage"$sigma".txt | sort | uniq >> $testing`
#echo $whoip
#testing="/home/user/Scripts/testing.txt"
#IPlookup="/home/user/Scripts/iptest.txt"


#Preform Usage for the current hour
if
grep -v 1.1.1.1 $newlogs/adminusage"$sigma".txt
then
#whois $testing >> $IPlookup
mail -s "Admin Usage for $emaildate" email.com < $newlogs/adminusage"$sigma".txt
else
echo
fi

最佳答案

只需使用循环并每次迭代调用一次whois

假设您的 grep 返回一个换行符分隔的 IP 地址列表,您可以这样做:

grep ... | sort | uniq | while IFS= read -r ip ; do
    whois "$ip" >> whatever
done

关于linux - bash IP whois 查找脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9313121/

相关文章:

c - 用于进程内线程通信的posix队列与自定义0复制队列

bash - 无法使用cat和<< EOF通过SSH远程创建文件

json - 如何对 mongoDB 中的 db.currentOp() json 数组执行 group_by

linux - 在某些模式之前添加文本时将 sed 与忽略大小写一起使用

linux - .htaccess - 从 RewriteCond 中排除目录

bash - 'grep +A' : print everything after a match

linux - 在 shell 脚本中将文件路径读取为字符串

Bash 脚本 - 如何从文本文件中删除行/单词?

linux - 在 Shell 中动态重命名 XML 文件

linux - 无法使用带有文件描述符的群来锁定文件