Created
January 31, 2020 21:57
-
-
Save Oppodelldog/71363159654fd994aa393563cf50b5b5 to your computer and use it in GitHub Desktop.
port check
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
package main | |
import ( | |
"fmt" | |
"net" | |
"time" | |
) | |
func main() { | |
for port:=0; port <=8080 ; port++ { | |
if testPort(fmt.Sprintf("127.0.0.1:%v", port)){ | |
fmt.Println("OPEN",port) | |
} | |
} | |
} | |
func testPort(address string) bool { | |
conn, err := net.DialTimeout("tcp", address, time.Millisecond*200) | |
if err != nil { | |
return false | |
} | |
defer conn.Close() | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment