Skip to content

Instantly share code, notes, and snippets.

@billzhuang
Created September 10, 2020 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billzhuang/1c8d4b5bd53a0a6658c5c20fd119161c to your computer and use it in GitHub Desktop.
Save billzhuang/1c8d4b5bd53a0a6658c5c20fd119161c to your computer and use it in GitHub Desktop.
test local dead port
package main
import (
"fmt"
"net"
"os"
)
func main() {
arguments := os.Args
if len(arguments) == 1 {
fmt.Println("Please provide host:port.")
return
}
for i := 49152; i <= 65535; i++ {
dialTCP(arguments[1], i)
}
}
func dialTCP(target string, localPort int) {
CONNECT := target
dialer := &net.Dialer{
LocalAddr: &net.TCPAddr{
//IP: net.ParseIP("127.0.0.1"),
Port: localPort,
},
}
c, err := dialer.Dial("tcp", CONNECT)
if err != nil {
fmt.Printf("Connect with local port %d fail with error : %v \n", localPort, err)
return
}
fmt.Printf("Connect with local port %d succuss\n", localPort)
defer c.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment