summaryrefslogtreecommitdiff
path: root/rc/bin/iwhois
blob: 759635a5b1f5aad623f7982ca6f393dc72a862f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/rc
# print registration data for domain
rfork e
noboiler=()
if (~ $1 -n){
	noboiler=yes
	shift
}
if (~ $#* 0 || ~ $1 -*) {
	echo 'iwhois [-n] domain' >[1=2]
	exit usage
}
person=`{echo $1|sed s/@.*//}
fn boilerplate { sed '/>>> ?Last update of ..... database:/,$d' $* }

switch($1){
case *@*
	machine=`{echo $1|sed s/.*@//}
case *.ca
	machine=whois.cira.ca
	fn boilerplate { grep -v ':[	 ]*$' $* }
case *.us
	machine=whois.nic.us
	fn boilerplate { sed '/^>* Whois database was last updated on/,$d' $* }
case *.co.uk *.net.uk *.org.uk
	machine=whois.nic.uk
	fn boilerplate { sed '/^-- /,$d' $* }
case *.ac.uk
	machine=whois.ja.net
case *.au
	machine=whois.aunic.net
	fn boilerplate { grep -v ':[	 ]*$' $* }
case *.be
	machine=whois.dns.be
	person='-T dn '^$person
	fn boilerplate { cat $* }
case *.com *.net
	machine=whois.verisign-grs.com
case *.cn
	machine=whois.cnnic.net.cn
	fn boilerplate { cat $* }
case *.de
	machine=whois.denic.de
	person='-T dn '^$person
	fn boilerplate { cat $* }
case *.dk
	machine=whois.dk-hostmaster.dk
	fn boilerplate { grep -v '^#' $* }
case *.es
	echo no known whois server for .es >[1=2]
	exit '.es not supported'
case *.fr
	machine=whois.nic.fr
	fn boilerplate { grep -v '^%%' $* }
case *.in
	machine=whois.inregistry.net
	fn boilerplate { cat $* }
case *.jp
	machine=whois.jprs.jp
	person=$person^'/e'
	fn boilerplate { cat $* }
case *.org
	machine=whois.pir.org
case *.se
	machine=whois.nic-se.se
	fn boilerplate { grep -v '^#' $* | uniq }
case [0-9]*.[0-9]*.[0-9]*.[0-9]* *:*:*
	machine=whois.arin.net
	fn boilerplate { cat $* }
case *
	tld=`{echo $1 | sed 's;.*\.(.*)$;\1;'}
	if(ndb/dnsgetip whois.nic.$tld >/dev/null >[2=1])
		machine=whois.nic.$tld
	if not{
		machine=whois.internic.net	# alternate: whois.networksolutions.com
		fn boilerplate { cat $* }
	}
}
if(! ~ $#noboiler 0)
	fn boilerplate { cat $* }
file=/tmp/iwhois.$pid
fn sigexit {
	rm -f $file
}
echo $person | telnet -nr tcp!$machine!whois > $file
x=`{ tr A-Z a-z < $file | sed -n -e 's;.*whois server: ([^ /]+).*$;\1;p' \
	-e 's;.*referralserver: +whois://(.*)(:43)?;\1;p'}
switch($#x){
case 0
	;			# e.g., for .ca
case 1
	# chase the referral chain
	echo $person | telnet -nr tcp!$x!whois > $file
case *
#	echo $0: buggery: `{echo $x | tr ' ' '\12' | sort -u} >[1=2]
	echo $person | telnet -nr tcp!^$x(1)^!whois > $file
}
if (test ! -s $file) {
	echo $0: broken whois server tcp!$x!whois returned no data >[1=2]
	exit broken
}
boilerplate $file