commit 08600ffa4aedd23ce97653ddc5b009f469139f4c
parent 7e0cdb06392794410ea7ea296947f3382bcf952c
Author: Jacob R. Edwards <n/a>
Date: Sat, 12 Feb 2022 11:40:23 -0800
Add domain name availability checker script
Supports the xyz, org, net, and com TLDs and could be easily
extended to support more.
Diffstat:
| A | local/bin/bin/netname | | | 82 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 82 insertions(+), 0 deletions(-)
diff --git a/local/bin/bin/netname b/local/bin/bin/netname
@@ -0,0 +1,82 @@
+#!/usr/local/plan9/bin/rc
+# Copyright 2022 Jacob R. Edwards
+# Check if name is available with multiple different TLDs
+#
+# Don't abuse. If you do I'm not responsable. (Isn't this obvious?)
+#
+# Supported TLDs:
+tlds = (xyz org net com)
+
+if (! ~ $#* 0) {
+ for (a in $*) {
+ if (! ~ $a $tlds) {
+ echo 'usage: '^$0^' [TLD ...]' >[1=2]
+ echo $a^': Unsupported TLD' >[1=2]
+ exit 'Unsupported TLD'
+ }
+ }
+ tlds = $*
+}
+
+# Perhaps not a name portable to other rcs
+fn '?' {
+ ?name = $1
+ shift
+ if (~ $#$?name 0)
+ $?name = $*
+}
+
+# General function; called once $found and $notfound are set
+fn gen {
+ awk '{
+ printf "%s.%s: ", ENVIRON["name"], ENVIRON["tld"]
+ }
+ $0 ~ ENVIRON["notfound"] {
+ print "Available"
+ exit 0
+ }
+ $0 ~ ENVIRON["found"] {
+ print "Unavailable"
+ exit 1
+ }
+ {
+ print "Status unknown"
+ exit 2
+ }'
+}
+
+fn xyz {
+ ? notfound '.*NOT FOUND$'
+ ? found ' *Domain Name:'
+ gen
+}
+
+fn org {
+ xyz
+}
+
+fn net {
+ ? notfound '^No match for '
+ xyz
+}
+
+fn com {
+ net
+}
+
+while (name = `{ read }) {
+ if (~ $name *.* '') {
+ echo 'Invalid name' >[1=2]
+ status = 'Invalid name'
+ }
+ if not {
+ # Prevent very high-frequentcy requests
+ if (! ~ $#time 0 && test $time -eq `{ date +%s })
+ sleep 1
+ for (tld in $tlds) @{
+ whois -Q $name^.^$tld | $tld
+ }
+ # Setting time after lengthens the delay a hair
+ time = `{ date +%s }
+ }
+}