2012-02-16 81 views
2

我有一個體面的管理腳本,用於檢查哪些IP地址也是在Web應用程序上登錄,但我需要在開始時更加喜歡whois,然後我認爲是geoip。bash IP whois查詢腳本

在我散列出它的whois的一部分的時刻 - 我的問題是,由於有多個IP地址 - 該域名註冊不知道該怎麼跟他們做

任何想法在這將是巨大的? 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 [email protected] $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 

回答

2

只需使用一個循環,並調用whois每次迭代

一次假設你的grep返回一個以換行符分隔的IP地址列表,你可以這樣做:

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

如果您有多個IP地址,只需在他們環路和WHOIS在每次運行:

for address is $whoip ; do 
    whois $address 
done