From 4f40cdfb3f5003748aa1a1e18313cd7c27d7cc0d Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 20 May 2008 21:03:48 +0200 Subject: [PATCH] Allow setting the destination port in "dowkd host" --- dowkd.in | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/dowkd.in b/dowkd.in index 966a441..c8b2b1b 100644 --- a/dowkd.in +++ b/dowkd.in @@ -36,6 +36,7 @@ COMMAND is one of: file: examine files on the command line for weak keys host: examine the specified hosts for weak SSH keys + (change destination port with "host -p PORT HOST...") user: examine user SSH keys for weakness; examine all users if no users are given help: show this help screen @@ -385,8 +386,8 @@ sub from_pem ($) { return $found; } -sub from_ssh_host (@) { - my @names = @_; +sub from_ssh_host ($@) { + my ($port, @names) = @_; @names = grep { my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname $_; @@ -395,8 +396,8 @@ sub from_ssh_host (@) { } @names; my @lines; - push @lines, safe_backtick qw/ssh-keyscan -t rsa/, @names; - push @lines, safe_backtick qw/ssh-keyscan -t dsa/, @names; + push @lines, safe_backtick qw/ssh-keyscan -t rsa -p/, $port, @names; + push @lines, safe_backtick qw/ssh-keyscan -t dsa -p/, $port, @names; my $tmp = new File::Temp; for my $line (@lines) { @@ -448,7 +449,25 @@ if (@ARGV) { from_ssh_auth_file $name; } } elsif ($cmd eq 'host') { - from_ssh_host @ARGV; + unless (@ARGV) { + help; + exit 1; + } + my $port = 22; + if ($ARGV[0] eq '-p') { + shift @ARGV; + if (@ARGV) { + $port = shift @ARGV; + } + } elsif ($ARGV[0] =~ /-p(\d+)/) { + $port = $1; + shift @ARGV; + } + unless (@ARGV) { + help; + exit 1; + } + from_ssh_host $port, @ARGV; } elsif ($cmd eq 'user') { if (@ARGV) { from_user $_ for @ARGV; -- 2.11.4.GIT