utility.go changes
This commit is contained in:
parent
54817aa08d
commit
7f71198296
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -106,8 +107,8 @@ func Process(mon *Monitor) {
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
st := string(obj)
|
st := strings.TrimSpace(string(obj))
|
||||||
ipnet, domain, err := ParseInput(st[:len(st)-1]) //remove newline
|
ipnet, domain, err := ParseTarget(st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
|
17
utility.go
17
utility.go
@ -15,7 +15,8 @@ func init() {
|
|||||||
parser = flags.NewParser(&config, flags.Default)
|
parser = flags.NewParser(&config, flags.Default)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCommand adds a module to the parser and returns a pointer to a flags.command object or an error
|
// AddCommand adds a module to the parser and returns a pointer to
|
||||||
|
// a flags.command object or an error
|
||||||
func AddCommand(command string, shortDescription string, longDescription string, port int, m ScanModule) (*flags.Command, error) {
|
func AddCommand(command string, shortDescription string, longDescription string, port int, m ScanModule) (*flags.Command, error) {
|
||||||
cmd, err := parser.AddCommand(command, shortDescription, longDescription, m)
|
cmd, err := parser.AddCommand(command, shortDescription, longDescription, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -26,7 +27,8 @@ func AddCommand(command string, shortDescription string, longDescription string,
|
|||||||
return cmd, nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseFlags abstracts away the parser and validates the framework configuration (global options) immediately after parsing
|
// ParseFlags abstracts away the parser and validates the framework
|
||||||
|
// configuration (global options) immediately after parsing
|
||||||
func ParseFlags() ([]string, error) {
|
func ParseFlags() ([]string, error) {
|
||||||
r, err := parser.Parse()
|
r, err := parser.Parse()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -35,8 +37,10 @@ func ParseFlags() ([]string, error) {
|
|||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseInput takes input as a string and parses it into either an IPNet (may have empty mask and just contain IP) , domain name, or errors, may return both IPNet and domain name
|
// ParseTarget takes input as a string and parses it into either an IPNet
|
||||||
func ParseInput(s string) (*net.IPNet, string, error) {
|
// (may have empty mask and just contain IP , domain name, or errors, may
|
||||||
|
// return both IPNet and domain name
|
||||||
|
func ParseTarget(s string) (*net.IPNet, string, error) {
|
||||||
i := strings.IndexByte(s, ',')
|
i := strings.IndexByte(s, ',')
|
||||||
j := strings.IndexByte(s, '/')
|
j := strings.IndexByte(s, '/')
|
||||||
|
|
||||||
@ -65,10 +69,11 @@ func ParseInput(s string) (*net.IPNet, string, error) {
|
|||||||
if len(str) != 2 {
|
if len(str) != 2 {
|
||||||
return nil, "", errors.New("malformed input")
|
return nil, "", errors.New("malformed input")
|
||||||
}
|
}
|
||||||
|
d := strings.TrimSpace(str[1])
|
||||||
if ip := net.ParseIP(str[0]); ip != nil {
|
if ip := net.ParseIP(str[0]); ip != nil {
|
||||||
return &net.IPNet{IP: ip}, str[1], nil
|
return &net.IPNet{IP: ip}, d, nil
|
||||||
}
|
}
|
||||||
return nil, str[1], nil
|
return nil, d, nil
|
||||||
}
|
}
|
||||||
return nil, "", nil
|
return nil, "", nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user