お前、誰よ

って思ったら WHOIS 引きますよね? 例えば apache のログ見てて「何このアドレス?」って思ったら当然のごとく whois でもって接続元がどこの誰だか調べてやるわけです。誰だ!

$ whois 59.106.108.77
% [whois.apnic.net node-3]
% Whois data copyright terms    http://www.apnic.net/db/dbcopyright.html

inetnum:        59.106.0.0 - 59.106.255.255
netname:        SAKURA
descr:          SAKURA Internet Inc.
descr:          1-8-14, Minami Honmachi, Chuo-ku, Osaka 541-0054, Japan
country:        JP
admin-c:        JNIC1-AP
tech-c:         JNIC1-AP
status:         ALLOCATED PORTABLE
remarks:        Email address for spam or abuse complaints : support@sakura.ad.jp
mnt-by:         MAINT-JPNIC
mnt-lower:      MAINT-JPNIC
changed:        hm-changed@apnic.net 20041013
changed:        ip-apnic@nic.ad.jp 20070523
source:         APNIC

role:           Japan Network Information Center
address:        Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda
address:        Chiyoda-ku, Tokyo 101-0047, Japan
country:        JP
phone:          +81-3-5297-2311
fax-no:         +81-3-5297-2312
e-mail:         hostmaster@nic.ad.jp
admin-c:        JI13-AP
tech-c:         JE53-AP
nic-hdl:        JNIC1-AP
mnt-by:         MAINT-JPNIC
changed:        hm-changed@apnic.net 20041222
changed:        hm-changed@apnic.net 20050324
changed:        ip-apnic@nic.ad.jp 20051027
source:         APNIC

inetnum:        59.106.108.64 - 59.106.108.127
netname:        HATENA
descr:          Hatena Co.,Ltd.
country:        JP
admin-c:        ND406JP
tech-c:         ND406JP
remarks:        This information has been partially mirrored by APNIC from
remarks:        JPNIC. To obtain more specific information, please use the
remarks:        JPNIC WHOIS Gateway at
remarks:        http://www.nic.ad.jp/en/db/whois/en-gateway.html or
remarks:        whois.nic.ad.jp for WHOIS client. (The WHOIS client
remarks:        defaults to Japanese output, use the /e switch for English
remarks:        output)
changed:        apnic-ftp@nic.ad.jp 20061220
source:         JPNIC

はてなかー」って思ったりするわけです(フィクションです)

IP address で引いてみましたけどドメイン名でも引けちゃいます

$ whois hatena.ne.jp | nkf -w8
[ JPRS database provides information on network administration. Its use is    ]
[ restricted to network administration purposes. For further information,     ]
[ use 'whois -h whois.jprs.jp help'. To suppress Japanese output, add'/e'     ]
[ at the end of command, e.g. 'whois -h whois.jprs.jp xxx/e'.                 ]

Domain Information: [ドメイン情報]
a. [ドメイン名]                 HATENA.NE.JP
b. [ねっとわーくさーびすめい]   はてな
c. [ネットワークサービス名]     はてな
d. [Network Service Name]       hatena
k. [組織種別]                   ネットワークサービス
l. [Organization Type]          Network Service
m. [登録担当者]                 JK960JP
n. [技術連絡担当者]             JK961JP
n. [技術連絡担当者]             DT033JP
p. [ネームサーバ]               ns0.future-s.com
p. [ネームサーバ]               ns1.future-s.com
s. [署名鍵]                     
[状態]                          Connected (2011/02/28)
[登録年月日]                    2001/02/22
[接続年月日]                    2001/05/21
[最終更新]                      2010/03/01 01:24:24 (JST)
$ whois -h whois.jprs.jp JK960JP | nkf -w8
[ JPRS database provides information on network administration. Its use is    ]
[ restricted to network administration purposes. For further information,     ]
[ use 'whois -h whois.jprs.jp help'. To suppress Japanese output, add'/e'     ]
[ at the end of command, e.g. 'whois -h whois.jprs.jp xxx/e'.                 ]

Contact Information: [担当者情報]
a. [JPNICハンドル]              JK960JP
b. [氏名]                       近藤 淳也
c. [Last, First]                Kondo, Junya
d. [電子メイル]                 admin@hatena.ne.jp
f. [組織名]                     株式会社 はてな
g. [Organization]               Hatena Co., Ltd.
k. [部署]                        
l. [Division]                    
m. [肩書]                        
n. [Title]                       
o. [電話番号]                    
p. [FAX番号]                     
y. [通知アドレス]               jpnic-apply@future-s.com
[最終更新]                      2010/12/13 10:28:43 (JST)
                                form@dom.jprs.jp

で、思うわけです。「何だこの何でもありプロトコルは、[担当者情報] って属性JPバリバリやんけ」と。

WHOIS - Wikipedia によると RFC の 812, 954 を obsolete にして http://www.rfc-editor.org/rfc/rfc3912.txt が最新の RFC みたいなので眺めてみたところ

For historic reasons, WHOIS lacks many of the protocol design
attributes, for example internationalisation and strong security,
that would be expected from any recently-designed IETF protocol.
This document does not attempt to rectify any of those shortcomings.
Instead, this memo documents the WHOIS protocol as it is.

レガシーを気持ち良いくらいに引きずってる感じが臭ってきました。

リクエストの投げ方にしても

The WHOIS client makes a text request to the WHOIS server,
then the WHOIS server replies with text content. All requests are
terminated with ASCII CR and then ASCII LF.

すげーシンプル。コレくらいなら

>>> import socket
>>> sock = socket.socket()
>>> sock.connect(('whois.jprs.jp', 43))
>>> sock.send('hatena.ne.jp\n\r')
14
>>> print(sock.recv(10240).decode('iso-2022-jp'))
[ JPRS database provides information on network administration. Its use is    ]
[ restricted to network administration purposes. For further information,     ]
[ use 'whois -h whois.jprs.jp help'. To suppress Japanese output, add'/e'     ]
[ at the end of command, e.g. 'whois -h whois.jprs.jp xxx/e'.                 ]

Domain Information: [ドメイン情報]
a. [ドメイン名]                 HATENA.NE.JP
b. [ねっとわーくさーびすめい]   はてな
c. [ネットワークサービス名]     はてな
d. [Network Service Name]       hatena
k. [組織種別]                   ネットワークサービス
l. [Organization Type]          Network Service
m. [登録担当者]                 JK960JP
n. [技術連絡担当者]             JK961JP
n. [技術連絡担当者]             DT033JP
p. [ネームサーバ]               ns0.future-s.com
p. [ネームサーバ]               ns1.future-s.com
s. [署名鍵]                     
[状態]                          Connected (2011/02/28)
[登録年月日]                    2001/02/22
[接続年月日]                    2001/05/21
[最終更新]                      2010/03/01 01:24:24 (JST)

>>>

簡単。

でもこれ、パースしなさいって言われると途端に頭抱えますね。.JP はまだいいんだろうけど、世界中の WHOIS サーバ相手にすると思うと...

参照: PyCon Mini JP 「お前、誰よ」まとめ - Ian Lewis