iwhois 2.1 KB

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