-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsshlurp.go
More file actions
54 lines (49 loc) · 1.34 KB
/
sshlurp.go
File metadata and controls
54 lines (49 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
package main
import (
"encoding/json"
"fmt"
. "github.com/cmars/sshlurp-go.crypto/ssh"
"os"
)
func die(msg string) {
fmt.Fprintf(os.Stderr, "%s\n", msg)
os.Exit(1)
}
type SlurpKey struct {
Algo string `json:",omitempty"`
Fingerprint string `json:",omitempty"`
HostKey string `json:",omitempty"`
Err string `json:",omitempty"`
}
func main() {
config := &ClientConfig{}
if len(os.Args) < 2 {
die("Usage: <host:port>")
}
var results []*SlurpKey
for _, algo := range SlurpAlgos {
SetSlurpAlgo(algo)
key, err := DialASlurp("tcp", os.Args[1], config)
if err != nil {
results = append(results, &SlurpKey{Algo: algo, Err: err.Error()})
continue
}
hk, err := ParseHostKey(key)
if err != nil {
results = append(results, &SlurpKey{Algo: algo, Err: err.Error()})
continue
}
results = append(results, &SlurpKey{algo, hk.Fingerprint(), hk.KeyString(), ""})
}
out, err := json.MarshalIndent(results, "", "\t")
if err != nil {
die("Failed to format JSON: " + err.Error())
}
os.Stdout.Write(out)
}