add scanner info in -to-saas (#783)

This commit is contained in:
sadayuki-matsuno
2019-03-04 16:36:32 +09:00
committed by Kota Kanbe
parent 53f4a29fb1
commit e0e71b2eae
3 changed files with 52 additions and 38 deletions

View File

@@ -20,7 +20,6 @@ package scan
import (
"errors"
"fmt"
"net"
"net/http"
"os"
"path/filepath"
@@ -596,7 +595,7 @@ func scanVulns(jsonDir string, scannedAt time.Time, timeoutSec int) error {
}, timeoutSec)
hostname, _ := os.Hostname()
ipv4s, ipv6s, err := ip()
ipv4s, ipv6s, err := util.IP()
if err != nil {
util.Log.Errorf("Failed to fetch scannedIPs: %s", err)
}
@@ -627,38 +626,6 @@ func scanVulns(jsonDir string, scannedAt time.Time, timeoutSec int) error {
return nil
}
// ip returns scanner network ip addresses
func ip() (ipv4Addrs []string, ipv6Addrs []string, err error) {
ifaces, err := net.Interfaces()
if err != nil {
return nil, nil, err
}
for _, i := range ifaces {
addrs, _ := i.Addrs()
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
// only global unicast address
if !ip.IsGlobalUnicast() {
continue
}
if ok := ip.To4(); ok != nil {
ipv4Addrs = append(ipv4Addrs, ip.String())
} else {
ipv6Addrs = append(ipv6Addrs, ip.String())
}
}
}
return ipv4Addrs, ipv6Addrs, nil
}
// EnsureResultDir ensures the directory for scan results
func EnsureResultDir(scannedAt time.Time) (currentDir string, err error) {
jsonDirName := scannedAt.Format(time.RFC3339)