xref: /plan9/rc/bin/iwhois (revision d1be6b086622eecc0da76db1fbd64349a5e85293)
1#!/bin/rc
2# iwhois [-n] domain - print registration data for domain
3rfork e
4if (~ $#* 1 && ~ $1 -n)
5	noboiler=yes
6person=`{echo $1|sed s/@.*//}
7fn boilerplate { sed -n '/^[	 ]*[A-Za-z][A-Za-z]*:$/,$p' $* }
8
9switch($1){
10case *@*
11	machine=`{echo $1|sed s/.*@//}
12case *.ca
13	machine=whois.cira.ca
14	fn boilerplate { grep -v ':[	 ]*$' $* }
15case *.us
16	machine=whois.nic.us
17	fn boilerplate { sed '/^>* Whois database was last updated on/,$d' $* }
18case *.co.uk *.net.uk *.org.uk
19	machine=whois.nic.uk
20	fn boilerplate { sed '/^ +WHOIS database last updated at/,$d' $* }
21case *.ac.uk
22	machine=whois.ja.net
23case *.au
24	machine=whois.aunic.net
25	fn boilerplate { grep -v ':[	 ]*$' $* }
26case *.be
27	machine=whois.dns.be
28	person='-T dn '^$person
29	fn boilerplate { cat $* }
30case *.cn
31	machine=whois.cnnic.net.cn
32	fn boilerplate { cat $* }
33case *.de
34	machine=whois.denic.de
35	person='-T dn '^$person
36	fn boilerplate { cat $* }
37case *.dk
38	machine=whois.dk-hostmaster.dk
39	fn boilerplate { grep -v '^#' $* }
40case *.es
41	echo no known whois server for .es
42	exit
43case *.fr
44	machine=whois.nic.fr
45	fn boilerplate { grep -v '^%%' $* }
46case *.in
47	machine=whois.inregistry.net
48	fn boilerplate { cat $* }
49case *.jp
50	machine=whois.jprs.jp
51	person=$person^'/e'
52	fn boilerplate { cat $* }
53case *.se
54	machine=whois.nic-se.se
55	fn boilerplate { grep -v '^#' $* | uniq }
56case [0-9]*.[0-9]*.[0-9]*.[0-9]*
57	machine=whois.arin.net
58	fn boilerplate { cat $* }
59case *
60	machine=whois.internic.net	# alternate: whois.networksolutions.com
61	fn boilerplate { cat $* }
62}
63if (~ $noboiler yes)
64	fn boilerplate { cat $* }
65file=/tmp/iwhois$pid
66fn sigexit {
67	rm -f $file
68}
69echo $person | telnet -nr tcp!$machine!whois > $file
70x=`{ sed -n -e 's/.*Whois Server: (.*)/\1/p' \
71	-e 's;.*ReferralServer: whois://(.*)(:43)?;\1;p' $file }
72switch($#x){
73case 0
74	;			# e.g., for .ca
75case 1
76	# chase the referral chain
77	echo $person | telnet -nr tcp!$x!whois > $file
78case *
79#	echo $0: buggery: `{echo $x | tr ' ' '\12' | sort -u} >[1=2]
80	echo $person | telnet -nr tcp!^$x(1)^!whois > $file
81}
82if (test ! -s $file) {
83	echo $0: broken whois server tcp!$x!whois returned no data >[1=2]
84	exit broken
85}
86boilerplate $file
87rm $file
88