Skip to content

Instantly share code, notes, and snippets.

@ShawnMilo
Created February 26, 2018 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShawnMilo/cdbfc998e6651a0f1b97c8894692fb9e to your computer and use it in GitHub Desktop.
Save ShawnMilo/cdbfc998e6651a0f1b97c8894692fb9e to your computer and use it in GitHub Desktop.
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