Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiminwen committed Jul 25, 2017
0 parents commit 91ddd54
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rakefile
37 changes: 37 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"fmt"
"log"
"net"

"github.com/spf13/cobra"
)

var RootCmd = &cobra.Command{
Use: "porttester",
Short: "test if the tcp port is open",
Long: "A cross platform TCP port availability tester. Useful for firewall testing both host and external.",
Run: port_tester,
}

var host string
var port int

func init() {
RootCmd.PersistentFlags().StringVarP(&host, "hostname", "o", "", "hostname or ip to connect to")
RootCmd.PersistentFlags().IntVarP(&port, "port", "p", -1, "TCP port to test")
}

func port_tester(cmd *cobra.Command, args []string) {
addr := fmt.Sprintf("%s:%d", host, port)
conn, err := net.Dial("tcp", addr)

if err != nil {
log.Fatalf("Connection Failed: %v", err)
} else {
conn.Close()
}

log.Printf("Port %d is opened", port)
}
Binary file added porttester
Binary file not shown.
Binary file added porttester.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions porttester.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"log"
"os"

"./cmd"
)

func main() {
err := cmd.RootCmd.Execute()
if err != nil {
log.Printf("error to execute:%v", err)
os.Exit(1)
}
}
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# A simple port tester
A cross platform TCP port availability tester. Useful for firewall testing both host and external.

## Usage
```
./porttester -o host -p 8080
```

0 comments on commit 91ddd54

Please sign in to comment.