iwhois: add some improvements (thanks gall0ws)

patch from gall0ws:

> It's impossible to get whois right and probably nobody cares about it,
> nevertheless this small patch fixes some issues with the current version:
>
> * use a more common filter for default boilerplate (useful when
>   following the referral chain)
> * updated boilerplate for *.co.uk *.net.uk *.org.uk
> * added case *.com *.net (got it from iana.org)
> * use ARIN for IPv6 addresses
> * when unsure, check first whether whois.nic.$tld exists otherwise
>   usual fallback to InterNIC
> * fixed regexp for the referral chain (case, extra spaces or /)

- add usage handling.

--
cinap
This commit is contained in:
cinap_lenrek 2021-05-09 15:19:05 +02:00
parent 7048f1ca11
commit 014197f8d3

View file

@ -1,13 +1,17 @@
#!/bin/rc #!/bin/rc
# iwhois [-n] domain - print registration data for domain # print registration data for domain
rfork e rfork e
noboiler=() noboiler=()
if (! ~ $#* 0 && ~ $1 -n){ if (~ $1 -n){
noboiler=yes noboiler=yes
shift shift
} }
if (~ $#* 0 || ~ $1 -*) {
echo 'iwhois [-n] domain' >[1=2]
exit usage
}
person=`{echo $1|sed s/@.*//} person=`{echo $1|sed s/@.*//}
fn boilerplate { sed -n '/^[ ]*[A-Za-z][A-Za-z]*:$/,$p' $* } fn boilerplate { sed '/>>> ?Last update of ..... database:/,$d' $* }
switch($1){ switch($1){
case *@* case *@*
@ -20,7 +24,7 @@ case *.us
fn boilerplate { sed '/^>* Whois database was last updated on/,$d' $* } fn boilerplate { sed '/^>* Whois database was last updated on/,$d' $* }
case *.co.uk *.net.uk *.org.uk case *.co.uk *.net.uk *.org.uk
machine=whois.nic.uk machine=whois.nic.uk
fn boilerplate { sed '/^ +WHOIS database last updated at/,$d' $* } fn boilerplate { sed '/^-- /,$d' $* }
case *.ac.uk case *.ac.uk
machine=whois.ja.net machine=whois.ja.net
case *.au case *.au
@ -30,6 +34,8 @@ case *.be
machine=whois.dns.be machine=whois.dns.be
person='-T dn '^$person person='-T dn '^$person
fn boilerplate { cat $* } fn boilerplate { cat $* }
case *.com *.net
machine=whois.verisign-grs.com
case *.cn case *.cn
machine=whois.cnnic.net.cn machine=whois.cnnic.net.cn
fn boilerplate { cat $* } fn boilerplate { cat $* }
@ -55,16 +61,20 @@ case *.jp
fn boilerplate { cat $* } fn boilerplate { cat $* }
case *.org case *.org
machine=whois.pir.org machine=whois.pir.org
fn boilerplate { sed '/^>>> Last update of WHOIS database/,$d' $* }
case *.se case *.se
machine=whois.nic-se.se machine=whois.nic-se.se
fn boilerplate { grep -v '^#' $* | uniq } fn boilerplate { grep -v '^#' $* | uniq }
case [0-9]*.[0-9]*.[0-9]*.[0-9]* case [0-9]*.[0-9]*.[0-9]*.[0-9]* *:*:*
machine=whois.arin.net machine=whois.arin.net
fn boilerplate { cat $* } fn boilerplate { cat $* }
case * case *
machine=whois.internic.net # alternate: whois.networksolutions.com tld=`{echo $1 | sed 's;.*\.(.*)$;\1;'}
fn boilerplate { cat $* } 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) if(! ~ $#noboiler 0)
fn boilerplate { cat $* } fn boilerplate { cat $* }
@ -73,8 +83,8 @@ fn sigexit {
rm -f $file rm -f $file
} }
echo $person | telnet -nr tcp!$machine!whois > $file echo $person | telnet -nr tcp!$machine!whois > $file
x=`{ sed -n -e 's/.*Whois Server: (.*)/\1/p' \ x=`{ tr A-Z a-z < $file | sed -n -e 's;.*whois server: ([^ /]+).*$;\1;p' \
-e 's;.*ReferralServer: whois://(.*)(:43)?;\1;p' $file } -e 's;.*referralserver: +whois://(.*)(:43)?;\1;p'}
switch($#x){ switch($#x){
case 0 case 0
; # e.g., for .ca ; # e.g., for .ca