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ループを使用して、反復ごとに 1 回呼び出すだけです

改行で区切られた IP アドレスのリストを返すと仮定すると、grep次のようにすることができます。

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

複数の IP がある場合は、単純にそれらをループして、それぞれで whois を実行します。

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