summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appl/cmd/mkfile1
-rw-r--r--appl/cmd/uniq.b15
-rw-r--r--appl/cmd/whois.b89
-rw-r--r--man/1/uniq5
-rw-r--r--man/1/whois40
5 files changed, 146 insertions, 4 deletions
diff --git a/appl/cmd/mkfile b/appl/cmd/mkfile
index a158edaa..a3cc6c09 100644
--- a/appl/cmd/mkfile
+++ b/appl/cmd/mkfile
@@ -170,6 +170,7 @@ TARG=\
wav2iaf.dis\
wc.dis\
webgrab.dis\
+ whois.dis\
wish.dis\
wmexport.dis\
wmimport.dis\
diff --git a/appl/cmd/uniq.b b/appl/cmd/uniq.b
index 4442c22f..9846e69f 100644
--- a/appl/cmd/uniq.b
+++ b/appl/cmd/uniq.b
@@ -13,7 +13,7 @@ Uniq: module
usage()
{
- fail("usage", sys->sprint("usage: uniq [-ud] [file]"));
+ fail("usage", sys->sprint("usage: uniq [-udc] [file]"));
}
init(nil : ref Draw->Context, args : list of string)
@@ -31,6 +31,7 @@ init(nil : ref Draw->Context, args : list of string)
uflag := 0;
dflag := 0;
+ cflag := 0;
arg->init(args);
while ((opt := arg->opt()) != 0) {
case opt {
@@ -38,6 +39,8 @@ init(nil : ref Draw->Context, args : list of string)
uflag = 1;
'd' =>
dflag = 1;
+ 'c' =>
+ cflag = 1;
* =>
usage();
}
@@ -61,14 +64,20 @@ init(nil : ref Draw->Context, args : list of string)
if (s == prev)
n++;
else {
- if ((uflag && n == 1) || (dflag && n > 1))
+ if ((uflag && n == 1) || (dflag && n > 1)) {
+ if(cflag)
+ prev = string n + "\t" + prev;
stdout.puts(prev);
+ }
n = 1;
prev = s;
}
}
- if ((uflag && n == 1) || (dflag && n > 1))
+ if ((uflag && n == 1) || (dflag && n > 1)) {
+ if(cflag)
+ prev = string n + "\t" + prev;
stdout.puts(prev);
+ }
stdout.close();
}
diff --git a/appl/cmd/whois.b b/appl/cmd/whois.b
new file mode 100644
index 00000000..f89fb601
--- /dev/null
+++ b/appl/cmd/whois.b
@@ -0,0 +1,89 @@
+implement Whois;
+
+include "sys.m"; sys: Sys;
+include "draw.m";
+include "dial.m"; dial: Dial;
+include "arg.m";
+
+Whois: module {
+ init: fn(nil: ref Draw->Context, args: list of string);
+};
+
+init(nil: ref Draw->Context, args: list of string) {
+ sys = load Sys Sys->PATH;
+ dial = load Dial Dial->PATH;
+ arg := load Arg Arg->PATH;
+
+ addr := "tcp!whois.iana.org!43";
+ expect_refer := 5;
+
+ arg->init(args);
+ arg->setusage("whois [-a addr] [-n] host");
+ while((opt := arg->opt()) != 0) {
+ case opt {
+ 'a' =>
+ addr = dial->netmkaddr(arg->earg(), "tcp", "43");
+ 'n' =>
+ expect_refer = 0;
+ * =>
+ arg->usage();
+ }
+ }
+
+ args = arg->argv();
+ if(len args != 1)
+ arg->usage();
+
+ host := hd args;
+ fd := whois(addr, host);
+
+ buf := array[512] of byte;
+ stdout := sys->fildes(1);
+ while((i := sys->read(fd, buf, len buf)) > 0) {
+ if(expect_refer) {
+ ls := sys->tokenize(string buf[0:i], "\n").t1;
+ newaddr: string = nil;
+ while(ls != nil) {
+ l := hd ls;
+ (n, rs) := sys->tokenize(l, " \t");
+ if(n == 2 && hd rs == "refer:") {
+ newaddr = dial->netmkaddr(hd tl rs, "tcp", "43");
+ break;
+ } else if(n == 3 && hd rs == "Whois" && hd tl rs == "Server:") {
+ newaddr = dial->netmkaddr(hd tl tl rs, "tcp", "43");
+ break;
+ }
+ ls = tl ls;
+ }
+ if(newaddr != nil) {
+ fd = whois(newaddr, host);
+ expect_refer--;
+ continue;
+ }
+ }
+ sys->write(stdout, buf, i);
+ }
+ if(i < 0) {
+ sys->fprint(sys->fildes(2), "whois: reading info: %r\n");
+ raise "fail:errors";
+ }
+}
+
+whois(addr: string, host: string): ref Sys->FD
+{
+ sys->print("[using server %s]\n", addr);
+ conn := dial->dial(addr, nil);
+ if(conn == nil) {
+ sys->fprint(sys->fildes(2), "whois: dialing %s: %r\n", addr);
+ raise "fail:errors";
+ }
+
+ fd := conn.dfd;
+ i := sys->fprint(fd, "%s\r\n", host);
+ if(i != len host + 2) {
+ sys->fprint(sys->fildes(2), "whois: sending name: %r\n");
+ raise "fail:errors";
+ }
+
+ return fd;
+}
diff --git a/man/1/uniq b/man/1/uniq
index 408e9600..41701bca 100644
--- a/man/1/uniq
+++ b/man/1/uniq
@@ -4,7 +4,7 @@ uniq \- report repeated lines in a file
.SH SYNOPSIS
.B uniq
[
-.B -ud
+.B -udc
]
[
.I file
@@ -24,6 +24,9 @@ in order to be found.
.B -u
Print unique lines.
.TP
+.B -c
+Prefix a repetition count and a tab to each output line.
+.TP
.B -d
Print (one copy of) duplicated lines.
.SH SOURCE
diff --git a/man/1/whois b/man/1/whois
new file mode 100644
index 00000000..dfaefe88
--- /dev/null
+++ b/man/1/whois
@@ -0,0 +1,40 @@
+.TH WHOIS 1
+.SH NAME
+whois \- query whois databases
+.SH SYNOPSIS
+.B whois
+[
+.B -a
+.I server
+]
+[
+.B -n
+]
+.I host
+.SH DESCRIPTION
+.I Whois
+queries whois servers to find owner information for domain names and
+network addresses. By default, it looks for referrals to other whois
+database servers and queries the next server in the chain if it finds
+one.
+
+.TP
+.B -a
+Specify a different server to start the query. (Default:
+.I tcp!whois.iana.org!43
+)
+.TP
+.B -n
+Do not attempt to follow referrals.
+.SH EXAMPLE
+To query for the owner of a domain and then an IP address, using a
+specific server while ignoring referrals to other servers:
+.IP
+.EX
+whois inferno-os.org
+whois -a whois.ripe.net -n 148.251.6.120
+.EE
+.SH SOURCE
+.B /appl/cmd/whois.b
+.SH "SEE ALSO"
+.IR RFC3912