|
|
apache 用の国別拒否リスト作成 |
H.Kamifuji |
apache 用の国別拒否リスト作成するサンプルです。ここの世界の国別 IPV4 アドレス割り当てリストを参考にさせていただき作成しました。 Linux 用の CL アプリと Windows 用の GUI アプリを作成したので紹介します。 |
この IP_Filter.tar.gz をダウンロードして、適当なディレクトリで解凍してください。 解凍されたディレクトリに移動( cd IP_Filter )して、Makefile 内の BINDIR を適宜変更してください。特定のログイン・ユーザの元で実行するときには、~/bin のままで良いです。 Makefile の編集後、下記のように make install コマンドを実行してください。 [xxxxxxxx@yyyyyyyyy IP_Filter]$ make install gcc -c strpos.c gcc -o ip_filter ip_filter.c strpos.o -lm cp ip_filter \ ~/bin [xxxxxxxx@yyyyyyyyy IP_Filter]$同梱されている getRIR ファイルには、下記のような shell プログラムが格納されています。 #!/bin/bash wget ftp://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest wget ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-extended-latest wget ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-extended-latest wget ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-extended-latest wget ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-extended-latest ip_filter CN del* ip_filter KR del* ip_filter KP del* ip_filter RU del* ip_filter ID del* ip_filter IN del*これで、delegated* データのダウンロードして、国別拒否リスト作成まで、1 コマンドで、実行できます。 プログラムの内容は、下記のページを参照してください。 世界の国別 IPV4 アドレス割り当てリスト RIR statistics exchange format |
この IP_Filter_CL.zip をダウンロードして、適当なディレクトリで解凍してください。 cl コマンドが利用(*1)できる cmd ( コマンドプロンプト )を開き、解凍されたディレクトリに移動( cd IP_Filter_CL )して、make.bat を実行してください。 E:\xxx...\IP_Filter_CL>make.bat E:\xxx...\IP_Filter_CL> cl ip_filter.cpp strpos.cpp Microsoft(R) C/C++ Optimizing Compiler Version 19.20.27508.1 for x64 Copyright (C) Microsoft Corporation. All rights reserved. ip_filter.cpp strpos.cpp コードを生成中... Microsoft (R) Incremental Linker Version 14.20.27508.1 Copyright (C) Microsoft Corporation. All rights reserved. /out:ip_filter.exe ip_filter.obj strpos.obj E:\xxx...\IP_Filter_CL>IP_Filter_CL ディレクトリには、当方でコンパイルした、下記の実行モジュールを同梱しています ip_filter_32.exe // 32bit OS 用 ip_filter_64.exe // 64bit OS 用 ip_filter_x86.exe // x86 OS 用 ip_filter_x64.exe // x64 OS 用同梱されている getRIR.bat ファイルには、下記のような bat プログラムが格納されています。 wget ftp://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest wget ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-extended-latest wget ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-extended-latest wget ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-extended-latest wget ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-extended-latest set p1="delegated-afrinic-extended-latest" set p2="delegated-apnic-extended-latest" set p3="delegated-arin-extended-latest" set p4="delegated-lacnic-extended-latest" set p5="delegated-ripencc-extended-latest" ip_filter_64 CN %p1% %p2% %p3% %p4% %p5% ip_filter_64 KR %p1% %p2% %p3% %p4% %p5% ip_filter_64 KP %p1% %p2% %p3% %p4% %p5% ip_filter_64 RU %p1% %p2% %p3% %p4% %p5% ip_filter_64 ID %p1% %p2% %p3% %p4% %p5% ip_filter_64 IN %p1% %p2% %p3% %p4% %p5%コンパイルされた ip_filter_xx.exe と getRIR.bat を path の通ったディレクトリにコピーして、空のディレクトリに移動して getRIR.bat を実行してください。path を通すには、環境変数 path の設定方法を参照してください。 E:\xxx...\work>getRIR.bat ---- 省略 ----- E:\xxx...\work>上記で、使用している wget コマンドは、ディフォルトで、インストールされていません。Wget for Windows からダウンロードして、インストールしてください。 これで、delegated* データのダウンロードして、国別拒否リスト作成まで、1 コマンドで、実行できます。
|
この IP_Filter.zip をダウンロードして、適当なディレクトリで解凍してください。解凍されたディレクトリには、Visual Studio 2019 のプロジェクトです。プロパティのプラットフォームツールセットを変更することで、Visual Studio 2010 まで遡ることが可能です。 Visual Studio が無くても、Release ディレクトリの IP_Filter.exe だけで、稼働できます。 詳細な説明は、省略しまが、アプリの顔だけです。 ![]() |
作成された国別拒否リストは、下記のようなファイル名で、保存されます。_cc.deny cc は、国別識別子です。Linux の場合は、下記のようなコマンドで、1つのファイルに合成できます。 [xxxxxxxx@yyyyyyyyy IP_Filter]$ cat _* > all.deny [xxxxxxxx@yyyyyyyyy IP_Filter]$作成された国別拒否リストは、apache の httpd.conf や .htaccess に貼り付けて、利用できます。 当方のサーバーでは、比較的に不正アクセスが多い(のみ)の CN KR KP RU ID IN をブロックしています。 RIR は、毎日、更新されているようなので、このようなツールを作成し、自動設定にチャレンジしています。 |
|