3

我有一个不错的管理脚本,用于检查哪些 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
4

2 回答 2

3

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

假设您grep返回一个以换行符分隔的 IP 地址列表,您可以执行以下操作:

grep ... | sort | uniq | while IFS= read -r ip ; do
    whois "$ip" >> whatever
done
于 2012-02-16T15:36:15.800 回答
0

如果您有多个 IP,只需遍历它们并在每个 IP 上运行 whois:

for address is $whoip ; do
    whois $address
done
于 2012-02-16T15:35:37.913 回答