Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions cmd/sshchecker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,29 @@ func processFromStdin(ctx context.Context, options *sshchecker.BatchOptions) {
output := make(chan *sshchecker.BatchResult)
var batchError error

addrCtx, cancel := context.WithCancel(ctx)
go func() {
batchError = sshchecker.BatchTrySSHLogin(ctx, addr, options, output)
batchError = sshchecker.BatchTrySSHLogin(addrCtx, addr, options, output)
close(output)
}()

success := false
for out := range output {
if out.Error != nil {
gologger.Warningf("[!] Failed to login on %s with %s:%s, error: %v",
addr.String(), out.Username, out.Password, out.Error)
if !success {
gologger.Warningf("[!] Failed to login on %s with %s:%s, error: %v",
addr.String(), out.Username, out.Password, out.Error)
}
continue
}

gologger.Infof("[+] Successful login on %s with %s:%s", addr.String(), out.Username, out.Password)
break

if !success {
gologger.Infof("[+] Successful login on %s with %s:%s", addr.String(), out.Username, out.Password)
cancel()
success = true
}
}
cancel()

if batchError != nil {
gologger.Warningf("[!] Error while batch logging in on %s: %v", addr.String(), batchError)
Expand Down