Files
maze 81a3829382 Refactoring
Refactored Protocol.Name -> Protocol.Type; added Encapsulation field
Refactored TLS parsing; added support for ALPN
2025-10-10 12:41:44 +02:00

46 lines
1.2 KiB
Go

// Command dpi-protocol-probe for probing network server protocols.
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.Type, protocol.Version, confidence*100)
}