サーバを立てているとあちこちから不正アクセスがくるもので、特に不正アクセスが多い国はアクセス禁止にしているサイトもあると思います。
そこで、どの国がどの IPを使っているかは、IPを管理している組織 IANA(Internet Assigned Numbers Authority) で調べることができます。といっても、IANAは地域別に以下のように分かれているので、実際の国別のIPの管理はこれらの組織が行っていますが、どこにリストがあってどうやって見ればよいかよくわからなかったので、調べてみました。組織へのリンクと、割り当てのリストへのリンク(allocation and assignment reports)です。delegated-apnic-日付というファイル名でアップロードされています。
- ARIN (allocation and assignment reports) … アメリカ方面に割り振られた IP アドレスを管理
- APNIC (allocation and assignment reports) … アジアに割り振られた IP アドレスを管理
- RIPE-NCC (allocation and assignment reports) … ヨーロッパに割り振られた IP アドレスを管理
- LACNIC (allocation and assignment reports) … ラテンアメリカとカリブ海諸島に割り振られた IP アドレスを管理
ファイルには、以下のようなリストが載っています。ipv4と書いてある行が調査の対象行です。
apnic|NZ|asn|2.102|1|20090305|allocated apnic|NZ|asn|2.104|1|20090409|allocated apnic|AU|asn|2.105|1|20090421|allocated ・・・ apnic|JP|ipv4|58.0.0.0|131072|20050106|allocated apnic|IN|ipv4|58.2.0.0|65536|20050110|allocated apnic|JP|ipv4|58.3.0.0|32768|20050304|allocated ・・・・
ヘッダにフォーマットの説明へのリンクが載っていましたので見てみたところ、以下のようなフォーマットらしいです。(サイトから引用)
registry|cc|type|start|value|date|status[|extensions...]
registry | One value from the set of defined strings:
{afrinic,apnic,arin,iana,lacnic,ripencc}; |
cc | ISO 3166 2-letter code of the organisation to which the allocation or assignment was made, and the enumerated variances of:
{AP,EU,UK} These values are not defined in ISO 3166 but are widely used. |
type | Type of Internet number resource represented in this record. One value from the set of defined strings:{asn,ipv4,ipv6} |
start | In the case of records of type ‘ipv4’ or ‘ipv6’ this is the IPv4 or IPv6 ‘first address’ of the range.In the case of an 16 bit AS number the format is the integer value in the range 0 to 65535, in the case of a 32 bit ASN the value is in the range 0 to 4294967296. No distinction is drawn between 16 and 32 bit ASN values in the range 0 to 65535. |
value | In the case of IPv4 address the count of hosts for this range. This count does not have to represent a CIDR range.In the case of an IPv6 address the value will be the CIDR prefix length from the ‘first address’ value of <start>.In the case of records of type ‘asn’ the number is the count of AS from this start value. |
status | Type of allocation from the set:
{allocated, assigned} This is the allocation or assignment made by the registry producing the file and not any sub-assignment by other agencies. |
extensions | Any extra data on a line is undefined, but should conform to use of the field separator used above. |
説明を読む限り、startが割り当て開始のIPアドレス、valueがそのアドレスから割り当てられているIPアドレス数のようです。
つまり以下の行の場合、
apnic|JP|ipv4|58.65.32.0|8192|20060921|allocated
JP(日本)に、58.65.32.0から8192個のIPのIPが割り当てられているということになります。これをIPの範囲で計算すると、8192/256=32なので、
58.65.32.0 ~ 58.65.63.255
となります。 計算できなくIPの基本を知らない人は別途勉強してください。
下記参考ページに、これらの計算を処理してくれるperlのスクリプトを公開してくれていますので、リストを作成したい場合は参照してみてください。
参考
http://fetus.k-hsu.net/document/network/ipv4assign/
http://www.nminoru.jp/~nminoru/memo/ip-address/what_country_from.html