From d57f4f01458307dd50f1607a04c42b21d392ee09 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Fri, 6 Jul 2018 09:48:28 -0400 Subject: [PATCH] cleanup Signed-off-by: Jess Frazelle --- k8scan/main.go | 52 +++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/k8scan/main.go b/k8scan/main.go index 5977d4c..1290800 100644 --- a/k8scan/main.go +++ b/k8scan/main.go @@ -60,30 +60,7 @@ func main() { go func(ip string) { defer wg.Done() - for port := beginPort; port <= endPort; port++ { - // Check if the port is open. - ok := portOpen(ip, port) - if !ok { - return - } - - // Check if it's a kubernetes dashboard. - ok = isKubernetesDashboard(ip, port) - if !ok { - return - } - - fmt.Printf("%s:%d\n", ip, port) - // Get the info for the ip address. - info, err := getIPInfo(ip) - if err != nil { - logrus.Warnf("ip info err: %v", err) - return - } - fmt.Printf("%s:%d\t%s\t%s\t%s\n", - ip, port, - info.Net.Organization.Handle, info.Net.Organization.Name, info.Net.Organization.Reference) - } + scanIP(ip) }(ip.String()) } @@ -93,6 +70,33 @@ func main() { logrus.Infof("Scan took: %s", since.String()) } +func scanIP(ip string) { + for port := beginPort; port <= endPort; port++ { + // Check if the port is open. + ok := portOpen(ip, port) + if !ok { + return + } + + // Check if it's a kubernetes dashboard. + ok = isKubernetesDashboard(ip, port) + if !ok { + return + } + + fmt.Printf("%s:%d\n", ip, port) + // Get the info for the ip address. + info, err := getIPInfo(ip) + if err != nil { + logrus.Warnf("ip info err: %v", err) + return + } + fmt.Printf("%s:%d\t%s\t%s\t%s\n", + ip, port, + info.Net.Organization.Handle, info.Net.Organization.Name, info.Net.Organization.Reference) + } +} + func portOpen(ip string, port int) bool { c, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), 2*time.Second) if err != nil {