Download raw body.
whois: trim output after ">>> Last update of WHOIS database:"
Currently whois(1) displays the full output it receives from the
server. With this change, any text after a line starting with
">>> Last update of WHOIS database:" is dropped. This trims a lot
of useless text that would otherwise cause the data you care about
to scroll off the screen.
From FreeBSD.
- todd
Index: usr.bin/whois/whois.1
===================================================================
RCS file: /cvs/src/usr.bin/whois/whois.1,v
retrieving revision 1.39
diff -u -p -u -r1.39 whois.1
--- usr.bin/whois/whois.1 5 Mar 2024 16:06:32 -0000 1.39
+++ usr.bin/whois/whois.1 15 Mar 2024 21:13:34 -0000
@@ -38,7 +38,7 @@
.Nd Internet domain name and network number directory service
.Sh SYNOPSIS
.Nm whois
-.Op Fl AadgIilmPQRr
+.Op Fl AadgIilmPQRrS
.Oo
.Fl c Ar country-code | Fl h Ar host
.Oc
@@ -201,6 +201,16 @@ Use the Reseaux IP Europeens
.Pq Tn RIPE
database.
It contains network numbers and domain contact information for Europe.
+.It Fl S
+By default
+.Nm
+adjusts simple queries (without spaces) to produce more useful output
+from certain whois servers, and it suppresses some uninformative output.
+With the
+.Fl S
+option,
+.Nm
+sends the query and prints the output verbatim.
.El
.Pp
The default action, unless directed otherwise with a special
Index: usr.bin/whois/whois.c
===================================================================
RCS file: /cvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.59
diff -u -p -u -r1.59 whois.c
--- usr.bin/whois/whois.c 5 Mar 2024 16:06:32 -0000 1.59
+++ usr.bin/whois/whois.c 15 Mar 2024 21:08:13 -0000
@@ -64,8 +64,11 @@
#define WHOIS_PORT "whois"
#define WHOIS_SERVER_ID "Registrar WHOIS Server:"
-#define WHOIS_RECURSE 0x01
-#define WHOIS_QUICK 0x02
+#define WHOIS_RECURSE 0x01
+#define WHOIS_QUICK 0x02
+#define WHOIS_SPAM_ME 0x04
+
+#define CHOPSPAM ">>> Last update of WHOIS database:"
const char *port_whois = WHOIS_PORT;
const char *ip_whois[] = { LNICHOST, RNICHOST, PNICHOST, BNICHOST,
@@ -83,7 +86,7 @@ main(int argc, char *argv[])
country = host = NULL;
flags = rval = 0;
- while ((ch = getopt(argc, argv, "aAc:dgh:iIlmp:PqQrR")) != -1)
+ while ((ch = getopt(argc, argv, "aAc:dgh:iIlmp:PqQrRS")) != -1)
switch (ch) {
case 'a':
host = ANICHOST;
@@ -133,6 +136,9 @@ main(int argc, char *argv[])
case 'R':
host = RUNICHOST;
break;
+ case 'S':
+ flags |= WHOIS_SPAM_ME;
+ break;
default:
usage();
}
@@ -206,11 +212,13 @@ whois(const char *query, const char *ser
return (1);
}
- if (strcmp(server, "whois.denic.de") == 0 ||
- strcmp(server, "de" QNICHOST_TAIL) == 0)
+ if (!(flags & WHOIS_SPAM_ME) &&
+ (strcmp(server, "whois.denic.de") == 0 ||
+ strcmp(server, "de" QNICHOST_TAIL) == 0))
fmt = "-T dn,ace -C ISO-8859-1 %s\r\n";
- else if (strcmp(server, "whois.dk-hostmaster.dk") == 0 ||
- strcmp(server, "dk" QNICHOST_TAIL) == 0)
+ else if (!(flags & WHOIS_SPAM_ME) &&
+ (strcmp(server, "whois.dk-hostmaster.dk") == 0 ||
+ strcmp(server, "dk" QNICHOST_TAIL) == 0))
fmt = "--show-handles %s\r\n";
else
fmt = "%s\r\n";
@@ -222,6 +230,11 @@ whois(const char *query, const char *ser
fflush(fp);
nhost = NULL;
while ((buf = fgetln(fp, &len)) != NULL) {
+ /* Nominet */
+ if (!(flags & WHOIS_SPAM_ME) &&
+ len == 5 && strncmp(buf, "-- \r\n", 5) == 0)
+ break;
+
p = buf + len - 1;
if (isspace((unsigned char)*p)) {
do
@@ -236,30 +249,38 @@ whois(const char *query, const char *ser
}
puts(buf);
- if (nhost != NULL || !(flags & WHOIS_RECURSE))
- continue;
-
- if ((p = strstr(buf, WHOIS_SERVER_ID))) {
- p += sizeof(WHOIS_SERVER_ID) - 1;
- while (isblank((unsigned char)*p))
- p++;
- if ((len = strcspn(p, " \t\n\r"))) {
- if ((nhost = malloc(len + 1)) == NULL)
- err(1, "malloc");
- memcpy(nhost, p, len);
- nhost[len] = '\0';
- }
- } else if (strcmp(server, ANICHOST) == 0) {
- for (p = buf; *p != '\0'; p++)
- *p = tolower((unsigned char)*p);
- for (i = 0; ip_whois[i] != NULL; i++) {
- if (strstr(buf, ip_whois[i]) != NULL) {
- nhost = strdup(ip_whois[i]);
- if (nhost == NULL)
- err(1, "strdup");
- break;
+ if (nhost == NULL && (flags & WHOIS_RECURSE)) {
+ if ((p = strstr(buf, WHOIS_SERVER_ID))) {
+ p += sizeof(WHOIS_SERVER_ID) - 1;
+ while (isblank((unsigned char)*p))
+ p++;
+ if ((len = strcspn(p, " \t\n\r"))) {
+ if ((nhost = malloc(len + 1)) == NULL)
+ err(1, "malloc");
+ memcpy(nhost, p, len);
+ nhost[len] = '\0';
+ }
+ } else if (strcmp(server, ANICHOST) == 0) {
+ for (p = buf; *p != '\0'; p++)
+ *p = tolower((unsigned char)*p);
+ for (i = 0; ip_whois[i] != NULL; i++) {
+ if (strstr(buf, ip_whois[i]) != NULL) {
+ nhost = strdup(ip_whois[i]);
+ if (nhost == NULL)
+ err(1, "strdup");
+ break;
+ }
}
}
+ }
+
+ /* Verisign etc. */
+ if (!(flags & WHOIS_SPAM_ME) &&
+ len >= sizeof(CHOPSPAM)-1 &&
+ (strncasecmp(buf, CHOPSPAM, sizeof(CHOPSPAM)-1) == 0 ||
+ strncasecmp(buf, &CHOPSPAM[4], sizeof(CHOPSPAM)-5) == 0)) {
+ printf("\n");
+ break;
}
}
fclose(fp);
whois: trim output after ">>> Last update of WHOIS database:"