Added Probe/ProbeTLS functions and demo command
This commit is contained in:
44
cmd/dpi-protocol-probe/main.go
Normal file
44
cmd/dpi-protocol-probe/main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.maze.io/go/dpi/protocol"
|
||||
)
|
||||
|
||||
func main() {
|
||||
networkFlag := flag.String("network", "tcp", "Network type to use for probing")
|
||||
timeoutFlag := flag.Duration("timeout", 30*time.Second, "Timeout")
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage of %s [<flags>] <address>:\n\n", os.Args[0])
|
||||
fmt.Fprintln(os.Stderr, "Available flags:")
|
||||
flag.PrintDefaults()
|
||||
fmt.Fprintln(os.Stderr, "\nRequired arguments:")
|
||||
fmt.Fprintln(os.Stderr, " address string")
|
||||
fmt.Fprintln(os.Stderr, "\tNetwork address to connect to (ie localhost:22)")
|
||||
os.Exit(0)
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() != 1 {
|
||||
flag.Usage()
|
||||
}
|
||||
|
||||
address := flag.Arg(0)
|
||||
if _, _, err := net.SplitHostPort(address); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
protocol, confidence, err := protocol.ProbeTimeout(*networkFlag, address, *timeoutFlag)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Probing address %q failed: %v\n", address, err)
|
||||
os.Exit(3)
|
||||
}
|
||||
|
||||
fmt.Printf("Protocol at address %q is %s version %s (confidence %g%%)\n", address, protocol.Name, protocol.Version, confidence*100)
|
||||
}
|
Reference in New Issue
Block a user