Created
September 10, 2020 09:46
-
-
Save billzhuang/1c8d4b5bd53a0a6658c5c20fd119161c to your computer and use it in GitHub Desktop.
test local dead port
This file contains hidden or 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
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