Skip to content

Instantly share code, notes, and snippets.

@ShawnMilo
Created February 26, 2018 02:19
Show Gist options
  • Save ShawnMilo/cdbfc998e6651a0f1b97c8894692fb9e to your computer and use it in GitHub Desktop.
Save ShawnMilo/cdbfc998e6651a0f1b97c8894692fb9e to your computer and use it in GitHub Desktop.

Revisions

  1. ShawnMilo created this gist Feb 26, 2018.
    36 changes: 36 additions & 0 deletions find_ssh.go
    Original 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)
    }
    }