ing
This commit is contained in:
parent
10be32e2b4
commit
b3e58106a9
|
@ -52,7 +52,7 @@ func Scan(discoverySession session.DiscoverySession) error {
|
|||
}
|
||||
delay.Store(true)
|
||||
if h := handlePacketARP(zone, targetHosts, hosts, packet); nil != h {
|
||||
go discoverySession.AddHost("ARP", h, nil)
|
||||
go discoverySession.AddHost(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumARP), h, nil)
|
||||
}
|
||||
case <-ticker.C:
|
||||
if false == delay.Load().(bool) {
|
||||
|
|
|
@ -65,7 +65,7 @@ func scanV4(discoverySession session.DiscoverySession) error {
|
|||
}
|
||||
delay.Store(true)
|
||||
if h := handlePacketICMP4(zone, targetHosts, hosts, packet); nil != h {
|
||||
go discoverySession.AddHost("ICMP", h, nil)
|
||||
go discoverySession.AddHost(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumICMP), h, nil)
|
||||
}
|
||||
case <-ticker.C:
|
||||
if false == delay.Load().(bool) {
|
||||
|
|
|
@ -54,7 +54,7 @@ func scanV6(discoverySession session.DiscoverySession) error {
|
|||
}
|
||||
delay.Store(true)
|
||||
if h := handlePacketICMP6(zone, targetHosts, hosts, packet); nil != h {
|
||||
go discoverySession.AddHost("ICMP", h, nil)
|
||||
go discoverySession.AddHost(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumICMP), h, nil)
|
||||
}
|
||||
case <-ticker.C:
|
||||
if false == delay.Load().(bool) {
|
||||
|
|
|
@ -73,7 +73,7 @@ SERVICE_LOOP:
|
|||
h.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
h = discoverySession.AddHost(
|
||||
"mDNS",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
|
||||
h,
|
||||
meta,
|
||||
)
|
||||
|
@ -90,7 +90,7 @@ SERVICE_LOOP:
|
|||
p.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
p = discoverySession.AddPort(
|
||||
"mDNS",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
|
||||
p,
|
||||
meta,
|
||||
)
|
||||
|
@ -104,7 +104,7 @@ SERVICE_LOOP:
|
|||
s.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddService(
|
||||
"mDNS",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
|
||||
s,
|
||||
meta,
|
||||
)
|
||||
|
@ -121,7 +121,7 @@ SERVICE_LOOP:
|
|||
h.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
h = discoverySession.AddHost(
|
||||
"mDNS",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
|
||||
h,
|
||||
meta,
|
||||
)
|
||||
|
@ -138,7 +138,7 @@ SERVICE_LOOP:
|
|||
p.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
p = discoverySession.AddPort(
|
||||
"mDNS",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
|
||||
p,
|
||||
meta,
|
||||
)
|
||||
|
@ -152,7 +152,7 @@ SERVICE_LOOP:
|
|||
s.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddService(
|
||||
"mDNS",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumMDNS),
|
||||
s,
|
||||
meta,
|
||||
)
|
||||
|
|
|
@ -151,7 +151,7 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
|
|||
h.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
h = discoverySession.AddHost(
|
||||
"SNMP V2c",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumSNMP),
|
||||
h,
|
||||
meta,
|
||||
)
|
||||
|
@ -164,7 +164,7 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
|
|||
p.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
p = discoverySession.AddPort(
|
||||
"SNMP V2c",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumSNMP),
|
||||
p,
|
||||
meta,
|
||||
)
|
||||
|
@ -180,7 +180,7 @@ func scanV2(target net.IP, discoverySession session.DiscoverySession, credential
|
|||
s.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddService(
|
||||
"SNMP V2c",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumSNMP),
|
||||
s,
|
||||
meta,
|
||||
)
|
||||
|
|
|
@ -101,7 +101,7 @@ func tryConnect(discoverySession session.DiscoverySession, ports map[int]*omd.Po
|
|||
|
||||
ports[port] = p
|
||||
|
||||
go discoverySession.AddPort("TCP Connection", p, nil)
|
||||
go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPConnection), p, nil)
|
||||
}
|
||||
|
||||
func Ulimit() int64 {
|
||||
|
|
|
@ -54,7 +54,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
|||
}
|
||||
delay.Store(true)
|
||||
if p := handlePacketTCP4(discoverySession, targetHost, ports, packet); nil != p {
|
||||
go discoverySession.AddPort("TCP SYN", p, nil)
|
||||
go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPSyn), p, nil)
|
||||
}
|
||||
case <-ticker.C:
|
||||
if false == delay.Load().(bool) {
|
||||
|
|
|
@ -101,7 +101,7 @@ func tryConnect(discoverySession session.DiscoverySession, ports map[int]*omd.Po
|
|||
|
||||
ports[port] = p
|
||||
|
||||
go discoverySession.AddPort("UDP Connection", p, nil)
|
||||
go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUDPConnection), p, nil)
|
||||
}
|
||||
|
||||
func Ulimit() int64 {
|
||||
|
|
|
@ -45,7 +45,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
|||
}
|
||||
delay.Store(true)
|
||||
if p := handlePacketUDP4(discoverySession, targetHost, ports, packet); nil != p {
|
||||
go discoverySession.AddPort("UDP Matcher", p, nil)
|
||||
go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUDPMatcher), p, nil)
|
||||
}
|
||||
case <-ticker.C:
|
||||
if false == delay.Load().(bool) {
|
||||
|
|
|
@ -75,7 +75,7 @@ LOOP:
|
|||
h.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddHost(
|
||||
"UPnP",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUPnP),
|
||||
h,
|
||||
meta,
|
||||
)
|
||||
|
@ -93,7 +93,7 @@ LOOP:
|
|||
p.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
p = discoverySession.AddPort(
|
||||
"UPnP",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUPnP),
|
||||
p,
|
||||
meta,
|
||||
)
|
||||
|
@ -123,7 +123,7 @@ LOOP:
|
|||
s.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddService(
|
||||
"UPnP",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUPnP),
|
||||
s,
|
||||
meta,
|
||||
)
|
||||
|
|
|
@ -43,10 +43,10 @@ type DiscoverySession interface {
|
|||
|
||||
SetDiscoveryDelegator(chan<- interface{})
|
||||
|
||||
AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host
|
||||
AddPort(discoveredBy string, port *omd.Port, meta map[string]string) *omd.Port
|
||||
AddService(discoveredBy string, service *omd.Service, meta map[string]string) *omd.Service
|
||||
AddServiceUnknown(discoveredBy string, port *omd.Port) *omd.Service
|
||||
AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host
|
||||
AddPort(discoveredBy *omm.MetaDiscovererType, port *omd.Port, meta map[string]string) *omd.Port
|
||||
AddService(discoveredBy *omm.MetaDiscovererType, service *omd.Service, meta map[string]string) *omd.Service
|
||||
AddServiceUnknown(discoveredBy *omm.MetaDiscovererType, port *omd.Port) *omd.Service
|
||||
|
||||
DiscoveredHost(address string) *omd.Host
|
||||
DiscoveredAllHosts(includeMac bool) map[string]*omd.Host
|
||||
|
@ -296,7 +296,7 @@ func (ds *ofDiscoverySession) IsTargetService(service *omd.Service) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host {
|
||||
func (ds *ofDiscoverySession) AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host {
|
||||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
|
@ -351,7 +351,7 @@ func (ds *ofDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta
|
|||
return h
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) AddPort(discoveredBy string, port *omd.Port, meta map[string]string) *omd.Port {
|
||||
func (ds *ofDiscoverySession) AddPort(discoveredBy *omm.MetaDiscovererType, port *omd.Port, meta map[string]string) *omd.Port {
|
||||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
|
@ -376,7 +376,7 @@ func (ds *ofDiscoverySession) AddPort(discoveredBy string, port *omd.Port, meta
|
|||
return p
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) AddService(discoveredBy string, service *omd.Service, meta map[string]string) *omd.Service {
|
||||
func (ds *ofDiscoverySession) AddService(discoveredBy *omm.MetaDiscovererType, service *omd.Service, meta map[string]string) *omd.Service {
|
||||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
|
@ -421,7 +421,7 @@ func (ds *ofDiscoverySession) AddService(discoveredBy string, service *omd.Servi
|
|||
return s
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) AddServiceUnknown(discoveredBy string, port *omd.Port) *omd.Service {
|
||||
func (ds *ofDiscoverySession) AddServiceUnknown(discoveredBy *omm.MetaDiscovererType, port *omd.Port) *omd.Service {
|
||||
if nil == ds.DiscoveredServices(port) {
|
||||
s := omd.NewService(
|
||||
port,
|
||||
|
@ -651,7 +651,7 @@ func (ds *ofDiscoverySession) findService(service *omd.Service) (s *omd.Service,
|
|||
return
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) addtionalHost(discoveredBy string, host *omd.Host) (h *omd.Host, modified bool) {
|
||||
func (ds *ofDiscoverySession) addtionalHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host) (h *omd.Host, modified bool) {
|
||||
h = host
|
||||
modified = false
|
||||
|
||||
|
@ -659,13 +659,13 @@ func (ds *ofDiscoverySession) addtionalHost(discoveredBy string, host *omd.Host)
|
|||
return
|
||||
}
|
||||
|
||||
meta, ok := host.Meta[discoveredBy]
|
||||
meta, ok := host.Meta[discoveredBy.Key]
|
||||
if !ok || nil == meta || 0 == len(meta) {
|
||||
return
|
||||
}
|
||||
|
||||
switch discoveredBy {
|
||||
case "mDNS":
|
||||
switch omm.ToMetaDiscovererTypeEnum(discoveredBy) {
|
||||
case omm.MetaDiscovererTypeEnumMDNS:
|
||||
_h, _modified := ds.addtionalHostMDNS(h, meta)
|
||||
if _modified {
|
||||
h = _h
|
||||
|
@ -698,7 +698,7 @@ func (ds *ofDiscoverySession) addtionalHostMDNS(host *omd.Host, meta map[string]
|
|||
return
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) addtionalService(discoveredBy string, service *omd.Service) (s *omd.Service, modified bool) {
|
||||
func (ds *ofDiscoverySession) addtionalService(discoveredBy *omm.MetaDiscovererType, service *omd.Service) (s *omd.Service, modified bool) {
|
||||
s = service
|
||||
modified = false
|
||||
|
||||
|
@ -706,13 +706,13 @@ func (ds *ofDiscoverySession) addtionalService(discoveredBy string, service *omd
|
|||
return
|
||||
}
|
||||
|
||||
meta, ok := service.Meta[discoveredBy]
|
||||
meta, ok := service.Meta[discoveredBy.Key]
|
||||
if !ok || nil == meta || 0 == len(meta) {
|
||||
return
|
||||
}
|
||||
|
||||
switch discoveredBy {
|
||||
case "mDNS":
|
||||
switch omm.ToMetaDiscovererTypeEnum(discoveredBy) {
|
||||
case omm.MetaDiscovererTypeEnumMDNS:
|
||||
_s, _modified := ds.addtionalServiceMDNS(s, meta)
|
||||
if _modified {
|
||||
s = _s
|
||||
|
@ -753,16 +753,16 @@ func (ds *ofDiscoverySession) addtionalServiceMDNS(service *omd.Service, meta ma
|
|||
return
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) appendDiscoveredBy(discoveredBy string, oriDiscoveredBy []string) (resultDiscoveredBy []string, modified bool) {
|
||||
func (ds *ofDiscoverySession) appendDiscoveredBy(discoveredBy *omm.MetaDiscovererType, oriDiscoveredBy []*omm.MetaDiscovererType) (resultDiscoveredBy []*omm.MetaDiscovererType, modified bool) {
|
||||
modified = false
|
||||
|
||||
if "" == discoveredBy {
|
||||
if "" == discoveredBy.Key {
|
||||
resultDiscoveredBy = oriDiscoveredBy
|
||||
return
|
||||
}
|
||||
|
||||
if nil == oriDiscoveredBy {
|
||||
resultDiscoveredBy = []string{
|
||||
resultDiscoveredBy = []*omm.MetaDiscovererType{
|
||||
discoveredBy,
|
||||
}
|
||||
modified = true
|
||||
|
@ -783,7 +783,7 @@ func (ds *ofDiscoverySession) appendDiscoveredBy(discoveredBy string, oriDiscove
|
|||
return
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) appendMeta(discoveredBy string, oriMetas map[string]map[string]string, newMeta map[string]string) (resultMetas map[string]map[string]string, modified bool) {
|
||||
func (ds *ofDiscoverySession) appendMeta(discoveredBy *omm.MetaDiscovererType, oriMetas map[string]map[string]string, newMeta map[string]string) (resultMetas map[string]map[string]string, modified bool) {
|
||||
modified = false
|
||||
if nil == newMeta || 0 == len(newMeta) {
|
||||
resultMetas = oriMetas
|
||||
|
@ -792,15 +792,15 @@ func (ds *ofDiscoverySession) appendMeta(discoveredBy string, oriMetas map[strin
|
|||
|
||||
if nil == oriMetas {
|
||||
resultMetas = map[string]map[string]string{
|
||||
discoveredBy: newMeta,
|
||||
discoveredBy.Key: newMeta,
|
||||
}
|
||||
modified = true
|
||||
return
|
||||
}
|
||||
|
||||
oriMeta, ok := oriMetas[discoveredBy]
|
||||
oriMeta, ok := oriMetas[discoveredBy.Key]
|
||||
if !ok {
|
||||
oriMetas[discoveredBy] = newMeta
|
||||
oriMetas[discoveredBy.Key] = newMeta
|
||||
resultMetas = oriMetas
|
||||
return
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"log"
|
||||
|
||||
omd "git.loafle.net/overflow/model/discovery"
|
||||
omm "git.loafle.net/overflow/model/meta"
|
||||
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
||||
)
|
||||
|
||||
|
@ -24,19 +25,19 @@ type mockDiscoverySession struct {
|
|||
ofDiscoverySession
|
||||
}
|
||||
|
||||
func (ds *mockDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host {
|
||||
func (ds *mockDiscoverySession) AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host {
|
||||
b, _ := json.Marshal(host)
|
||||
log.Print("Host: ", string(b))
|
||||
return ds.ofDiscoverySession.AddHost(discoveredBy, host, meta)
|
||||
}
|
||||
|
||||
func (ds *mockDiscoverySession) AddPort(discoveredBy string, port *omd.Port, meta map[string]string) *omd.Port {
|
||||
func (ds *mockDiscoverySession) AddPort(discoveredBy *omm.MetaDiscovererType, port *omd.Port, meta map[string]string) *omd.Port {
|
||||
b, _ := json.Marshal(port)
|
||||
log.Print("Port: ", string(b))
|
||||
return ds.ofDiscoverySession.AddPort(discoveredBy, port, meta)
|
||||
}
|
||||
|
||||
func (ds *mockDiscoverySession) AddService(discoveredBy string, service *omd.Service, meta map[string]string) *omd.Service {
|
||||
func (ds *mockDiscoverySession) AddService(discoveredBy *omm.MetaDiscovererType, service *omd.Service, meta map[string]string) *omd.Service {
|
||||
b, _ := json.Marshal(service)
|
||||
log.Print("Service: ", string(b))
|
||||
return ds.ofDiscoverySession.AddService(discoveredBy, service, meta)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
omd "git.loafle.net/overflow/model/discovery"
|
||||
omm "git.loafle.net/overflow/model/meta"
|
||||
omu "git.loafle.net/overflow/model/util"
|
||||
osm "git.loafle.net/overflow/service_matcher-go"
|
||||
ouej "git.loafle.net/overflow/util-go/encoding/json"
|
||||
|
@ -89,13 +90,13 @@ LOOP:
|
|||
s.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddService(
|
||||
"Service Matcher",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPMatcher),
|
||||
s,
|
||||
matchCtx.GetAttributes(),
|
||||
)
|
||||
} else {
|
||||
discoverySession.AddServiceUnknown(
|
||||
"Service Matcher",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPMatcher),
|
||||
targetPort,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ func scanUDP(discoverySession session.DiscoverySession, targetPort *omd.Port) er
|
|||
s.DiscoveredDate = omu.NowPtr()
|
||||
|
||||
discoverySession.AddService(
|
||||
"Service Matcher",
|
||||
omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumUDPMatcher),
|
||||
s,
|
||||
matchCtx.GetAttributes(),
|
||||
)
|
||||
|
|
12
ping/host/host.go
Normal file
12
ping/host/host.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
omcp "git.loafle.net/overflow/model/config/ping"
|
||||
omd "git.loafle.net/overflow/model/discovery"
|
||||
ounp "git.loafle.net/overflow/util-go/net/ping"
|
||||
)
|
||||
|
||||
func Ping(host *omd.Host, pingOption omcp.Option) (omcp.Result, error) {
|
||||
|
||||
return ounp.Ping(host.Address, pingOption)
|
||||
}
|
11
ping/service/service.go
Normal file
11
ping/service/service.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
omcp "git.loafle.net/overflow/model/config/ping"
|
||||
omd "git.loafle.net/overflow/model/discovery"
|
||||
)
|
||||
|
||||
func Ping(service *omd.Service, pingOption *omcp.PingOption) (*omcp.PingResult, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
|
@ -5,6 +5,8 @@ import (
|
|||
|
||||
oa "git.loafle.net/overflow/annotation-go"
|
||||
od "git.loafle.net/overflow/di-go"
|
||||
omcp "git.loafle.net/overflow/model/config/ping"
|
||||
omd "git.loafle.net/overflow/model/discovery"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -27,11 +29,12 @@ func (s *PingService) InitService() {
|
|||
func (s *PingService) DestroyService() {
|
||||
|
||||
}
|
||||
func (s *PingService) PingHost() error {
|
||||
|
||||
func (s *PingService) PingHost(host *omd.Host, pingOption *omcp.PingOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *PingService) PingService() error {
|
||||
func (s *PingService) PingService(host *omd.Service, pingOption *omcp.PingOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user