-.\" $OpenBSD: whois.1,v 1.39 2024/03/05 16:06:32 millert Exp $
+.\" $OpenBSD: whois.1,v 1.40 2024/03/16 02:00:31 millert Exp $
.\" $NetBSD: whois.1,v 1.5 1995/08/31 21:51:32 jtc Exp $
.\"
.\" Copyright (c) 1985, 1990, 1993
.\"
.\" @(#)whois.1 8.2 (Berkeley) 6/20/94
.\"
-.Dd $Mdocdate: March 5 2024 $
+.Dd $Mdocdate: March 16 2024 $
.Dt WHOIS 1
.Os
.Sh NAME
.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
.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
-/* $OpenBSD: whois.c,v 1.59 2024/03/05 16:06:32 millert Exp $ */
+/* $OpenBSD: whois.c,v 1.60 2024/03/16 02:00:31 millert Exp $ */
/*
* Copyright (c) 1980, 1993
#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,
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;
case 'R':
host = RUNICHOST;
break;
+ case 'S':
+ flags |= WHOIS_SPAM_ME;
+ break;
default:
usage();
}
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";
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
}
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);
free(nbuf);