Created
February 26, 2018 02:19
-
-
Save ShawnMilo/cdbfc998e6651a0f1b97c8894692fb9e to your computer and use it in GitHub Desktop.
Revisions
-
ShawnMilo created this gist
Feb 26, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ package main import ( "fmt" "net" "sync" "time" ) var addresses = make(chan string) var wg sync.WaitGroup func main() { for i := 0; i < 50; i++ { wg.Add(1) go trySSH() } for i := 1; i < 256; i++ { addresses <- fmt.Sprintf("192.168.86.%d:22", i) } close(addresses) wg.Wait() fmt.Println("done") } func trySSH() { defer wg.Done() for addr := range addresses { conn, err := net.DialTimeout("tcp", addr, time.Second*2) if err != nil { continue } conn.Close() fmt.Println(addr) } }