Created
February 26, 2018 02:19
-
-
Save ShawnMilo/cdbfc998e6651a0f1b97c8894692fb9e to your computer and use it in GitHub Desktop.
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 characters
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