4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【1分解説】Apacheのアクセスログ解析(アクセス元IPアドレスをTOP10で抽出)

Last updated at Posted at 2019-11-28

はじめに

アクセス元IPアドレスをTOP10で抽出したい!という時に使うコマンド。

発行コマンド

$ cat access_log |cut -f 1 -d ' ' | sort |uniq -c|sort -nr|head -10

中身

◆cut -f 1 -d ' ' access_logの中身を「 」(スペース)で区切り、1項目を表示する

◆sort | uniq -c
で重複行をカウント

◆sort -nr
数字が大きい順に並べかえる

◆head -10
TOP10のみ出力

実際に発行してみた

実際に発行してみると、
$ cat access_log |cut -f 1 -d ' ' | sort |uniq -c|sort -nr|head -10
103 X.X.X.X
99 X.X.X.X
93 X.X.X.X
91 X.X.X.X
88 X.X.X.X
50 X.X.X.X
33 X.X.X.X
29 X.X.X.X
18 X.X.X.X
6 X.X.X.X

左からアクセス数、つぎに接続元IPアドレスが出力されます。

例えば、接続数が多いIPアドレスが海外のブラックリストに登録されているIPアドレスだった場合は、拒否したりすることもできます。

4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?