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