diff --git a/README.md b/README.md index bc13644..a4b3cb6 100644 --- a/README.md +++ b/README.md @@ -22,21 +22,25 @@ Binaries are availables for GNU/Linux, MacOS and Windows ## Usage ```bash -# Knock to the server example.com at port 1337 (tcp), then 1338 (UDP) and finally 1339 (TCP) -open-go-knocking example.com 1337:tcp 1338:udp 1339:tcp +# Knock to the server 192.168.0.42 at port 1337 (tcp), then 1338 (UDP) and finally 1339 (TCP) +open-go-knocking 192.168.0.42 1337:tcp 1338:udp 1339:tcp # If the majority of ports are TCP ports, you can use the following syntax (ports without protocol will be in TCP) -open-go-knocking --tcp example.com 1337 1338:udp 1339 +open-go-knocking --tcp 192.168.0.42 1337 1338:udp 1339 # If the majority of ports are UDP ports, you can use the following syntax (ports without protocol will be in UDP) -open-go-knocking --udp example.com 1337 1338:tcp 1339 +open-go-knocking --udp 192.168.0.42 1337 1338:tcp 1339 + +# If you use domain name, you can increase the timeout to take account of resolution time +open-go-knocking --timeout 100 example.com 1337:tcp 1338:udp 1339:tcp ``` ## Options * `--tcp`: use TCP protocol by default * `--udp`: use UPD protocol by default -* `--delay` (in ms): delay in milliseconds between 2 packets send to host +* `--delay` (in ms / default 1): delay in milliseconds between 2 packets send to host +* `--timeout` (in ms / default 5): timeout in milliseconds before autoclose connection * `--version`: Show the current version * `--help`: Show the help diff --git a/main.go b/main.go index 7346d2a..5ffeb52 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,8 @@ var ( versionFlag = flag.Bool("version", false, "Show version") tcpFlag = flag.Bool("tcp", false, "Send all packets to TCP") udpFlag = flag.Bool("udp", false, "Send all packets to UDP") - delayFlag = flag.Int("delay", 5, "Delay between each packet (in milliseconds)") + delayFlag = flag.Int("delay", 1, "Delay between each packet (in milliseconds)") + timeoutFlag = flag.Int("timeout", 5, "Timeout before close connection") version = "develop" appName = "OpenGoKnocking" @@ -125,7 +126,7 @@ func getPacketsAndVerify() ([]packet) { func knock(host string, packet packet) { destination := net.JoinHostPort(host, strconv.Itoa(packet.Port)) - conn, err := net.DialTimeout(packet.Protocol, destination, 5 * time.Millisecond) + conn, err := net.DialTimeout(packet.Protocol, destination, time.Duration(*timeoutFlag) * time.Millisecond) if err != nil { // Expected error } else {