1
0
mirror of https://github.com/jessfraz/dockerfiles.git synced 2025-05-06 10:35:51 +02:00

reorganize

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-07-06 13:37:39 -04:00
parent c4901b1521
commit b99aa9d325
No known key found for this signature in database
GPG Key ID: C0B444E6A3EFD4C1

@ -56,12 +56,15 @@ func main() {
var wg sync.WaitGroup var wg sync.WaitGroup
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) { for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
for port := beginPort; port <= endPort; port++ {
wg.Add(1) wg.Add(1)
go func(ip string) { go func(ip string, port int) {
defer wg.Done() defer wg.Done()
scanIP(ip) scanIP(ip, port)
}(ip.String())
}(ip.String(), port)
}
} }
wg.Wait() wg.Wait()
@ -70,8 +73,7 @@ func main() {
logrus.Infof("Scan took: %s", since.String()) logrus.Infof("Scan took: %s", since.String())
} }
func scanIP(ip string) { func scanIP(ip string, port int) {
for port := beginPort; port <= endPort; port++ {
// Check if the port is open. // Check if the port is open.
ok := portOpen(ip, port) ok := portOpen(ip, port)
if !ok { if !ok {
@ -95,7 +97,6 @@ func scanIP(ip string) {
ip, port, ip, port,
info.Net.Organization.Handle, info.Net.Organization.Name, info.Net.Organization.Reference) info.Net.Organization.Handle, info.Net.Organization.Name, info.Net.Organization.Reference)
} }
}
func portOpen(ip string, port int) bool { func portOpen(ip string, port int) bool {
c, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), 2*time.Second) c, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), 2*time.Second)