Skip to content

Instantly share code, notes, and snippets.

@Oppodelldog
Created January 31, 2020 21:57
Show Gist options
  • Save Oppodelldog/71363159654fd994aa393563cf50b5b5 to your computer and use it in GitHub Desktop.
Save Oppodelldog/71363159654fd994aa393563cf50b5b5 to your computer and use it in GitHub Desktop.
port check
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