Linux bash IP whois 查找脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9313121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:36:58  来源:igfitidea点击:

bash IP whois lookup script

linuxbashshellwhois

提问by Grimlockz

I have a decent admin script working for checking what IPs are logging on too a web app but I need to make it more fancy with a whois at the start and then I thought a geoip.

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

At the moment I've hashed out the whois part of it - my problem is that because there are multiple IPs - the whois doesn't know what to do with them

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

Any ideas on this would be great? and also ideas on geoips would be lovely!

关于这个的任何想法会很棒吗?并且关于 geoips 的想法也会很可爱!

Cheers

干杯

#!/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 }')"

#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  }' | 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

采纳答案by sorpigal

Just use a loop and invoke whoisonce per iteration

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

Presuming that your grepreturns a newline-delimited list of IP addresses, you could do something like this:

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

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

回答by Wes Hardaker

If you have multiple IPs, simply loop over them and run whois on each:

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

for address is $whoip ; do
    whois $address
done