Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment