-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 91ddd54
Showing
6 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rakefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |