Added Probe/ProbeTLS functions and demo command

This commit is contained in:
2025-10-09 17:43:50 +02:00
parent 05686075c4
commit 97f3adbb31
2 changed files with 114 additions and 0 deletions

View 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)
}