From 7c057245732a7ddc98db99589bd49e69d9c27984 Mon Sep 17 00:00:00 2001 From: Jan Schaumann Date: Thu, 28 Sep 2023 16:06:25 -0400 Subject: [PATCH] allow multiple names to be checked --- doc/jswhois.1 | 3 ++- src/jswhois.go | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/doc/jswhois.1 b/doc/jswhois.1 index 7ed25e3..48535a1 100644 --- a/doc/jswhois.1 +++ b/doc/jswhois.1 @@ -1,4 +1,4 @@ -.Dd January 09, 2022 +.Dd September 28, 2023 .Dt jswhois 1 .Os .Sh NAME @@ -10,6 +10,7 @@ .Op Fl h Ar host .Op Fl p Ar port .Ar domain +.Op Ar ... .Sh DESCRIPTION The .Nm diff --git a/src/jswhois.go b/src/jswhois.go index cc8b4a7..8f7dbec 100644 --- a/src/jswhois.go +++ b/src/jswhois.go @@ -28,7 +28,7 @@ import ( ) const PROGNAME = "jswhois" -const VERSION = "1.0" +const VERSION = "1.1" const EXIT_FAILURE = 1 const EXIT_SUCCESS = 0 @@ -1140,13 +1140,6 @@ func getopts() { os.Args = os.Args[1:] } - - if len(os.Args) != 1 { - usage(os.Stderr) - os.Exit(EXIT_FAILURE) - } - - OUTPUT["query"] = os.Args[0] } func hasMarker(list map[string]bool, line string) (yesno bool) { @@ -1161,9 +1154,26 @@ func hasMarker(list map[string]bool, line string) (yesno bool) { } func lookupWhois() { + + var allOutput = []map[string]interface{}{} + verbose(1, "Looking up %d names...", len(os.Args)) + + for _, q := range os.Args { + OUTPUT = map[string]interface{}{} + OUTPUT["query"] = q + allOutput = append(allOutput, oneLookup()) + } + + j, _ := json.Marshal(allOutput) + fmt.Printf("%s\n", j) +} + + +func oneLookup() (rval map[string]interface{}) { + rval = map[string]interface{}{} query := OUTPUT["query"].(string) - verbose(1, "Looking up %s...", query) + verbose(2, "Looking up %s...", query) var chain = []string{DEFAULT_WHOIS} OUTPUT[DEFAULT_WHOIS] = askWhois(DEFAULT_WHOIS, query) @@ -1185,20 +1195,18 @@ func lookupWhois() { OUTPUT["chain"] = chain - var j []byte - if LEAF_ONLY { - leaf := map[string]interface{}{} - leaf["query"] = OUTPUT["query"] - leaf["chain"] = chain - leaf[chain[len(chain)-1]] = data - j, _ = json.Marshal(leaf) + rval["query"] = OUTPUT["query"] + rval["chain"] = chain + rval[chain[len(chain)-1]] = data } else { - j, _ = json.Marshal(OUTPUT) + rval = OUTPUT } - fmt.Printf("%s\n", j) + + return } + func printVersion() { fmt.Printf("%v version %v\n", PROGNAME, VERSION) }