Skip to content

Commit

Permalink
Add timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
leblanc-simon committed May 26, 2023
1 parent 1c2a7a9 commit ce7822d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ce7822d

Please sign in to comment.