184.13.80.102 - - [07/Jan/2019:00:33:10 -0500] "GET /?p=454 HTTP/1.1" 200 8822 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [07/Jan/2019:20:16:12 -0500] "GET /?p=454 HTTP/1.1" 200 8820 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0"
184.13.80.102 - - [07/Jan/2019:23:14:10 -0500] "GET /?p=454 HTTP/1.1" 200 8820 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [08/Jan/2019:02:32:22 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [08/Jan/2019:03:57:19 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [08/Jan/2019:23:05:32 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [09/Jan/2019:07:35:10 -0500] "GET /?p=454 HTTP/1.1" 200 8821 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [09/Jan/2019:14:45:36 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [09/Jan/2019:23:22:03 -0500] "GET /?p=454 HTTP/1.1" 200 8821 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [10/Jan/2019:23:50:28 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Linux i686; rv:60.0) Gecko/20100101 Firefox/60.0"
184.13.80.102 - - [13/Jan/2019:00:56:36 -0500] "GET /?p=454 HTTP/1.1" 200 8821 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [15/Jan/2019:20:47:56 -0500] "GET /?p=454 HTTP/1.1" 200 8819 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0"
184.13.80.102 - - [15/Jan/2019:22:36:09 -0500] "GET /?p=454 HTTP/1.1" 200 8821 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
该用户试图淹没我的服务器。我如何使用cat
或awk
检查access_log
特定并检测尝试访问服务器的ip
天数?ip
本例中为 6 天。
答案1
您可以使用命令:
grep "$ip" log_file | cut -d '[' -f2 | cut -d '/' -f1 | uniq | wc -l
假设ip address
要搜索的内容位于变量中ip
,并且log_file
是您的日志文件。
您可以将ip
变量定义为ip="184.13.80.102"
.
答案2
#!/bin/bash
echo "enter the ip"
read ip
awk -v i="$i" '/i/{print $4}' filename| sed "s/\[//g"| awk '{print substr($1,1,2)}'|awk '{if (!seen[$1]++)print $1}'| wc -l| sed "1i Below are Number of times "$ip" exsists"
output
Below are Number of times 184.13.80.102 exsists
6