ing
This commit is contained in:
parent
f74f259a88
commit
d47b62438a
23
main.go
23
main.go
|
@ -2,11 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
cRPC "git.loafle.net/commons_go/rpc"
|
||||
"git.loafle.net/overflow/ipc_client/rpc"
|
||||
oodamdm "git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
|
||||
"git.loafle.net/overflow/overflow_discovery/client"
|
||||
"git.loafle.net/overflow/overflow_discovery/rpc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -19,10 +20,11 @@ func main() {
|
|||
}
|
||||
|
||||
dz := newDiscoveryZone(true)
|
||||
if err := c.Notify("DiscoveryService.DiscoverZone", dz); nil != err {
|
||||
if err := c.Send("DiscoveryService.DiscoverZone", dz); nil != err {
|
||||
fmt.Printf("%v\n", err)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Minute)
|
||||
}
|
||||
|
||||
func newDiscoveryZone(includeDHost bool) *oodamdm.DiscoveryZone {
|
||||
|
@ -31,45 +33,44 @@ func newDiscoveryZone(includeDHost bool) *oodamdm.DiscoveryZone {
|
|||
}
|
||||
|
||||
if includeDHost {
|
||||
dz.DiscoveryHost = newDiscoveryHost(true, nil)
|
||||
dz.DiscoveryHost = newDiscoveryHost(true)
|
||||
}
|
||||
|
||||
return dz
|
||||
}
|
||||
|
||||
func newDiscoveryHost(includeDPort bool, zone *oodamdm.Zone) *oodamdm.DiscoveryHost {
|
||||
func newDiscoveryHost(includeDPort bool) *oodamdm.DiscoveryHost {
|
||||
dh := &oodamdm.DiscoveryHost{
|
||||
Zone: zone,
|
||||
FirstScanRange: "192.168.1.1",
|
||||
LastScanRange: "192.168.1.254",
|
||||
ExcludeHosts: []string{},
|
||||
}
|
||||
|
||||
if includeDPort {
|
||||
dh.DiscoveryPort = newDiscoveryPort(true, nil)
|
||||
dh.DiscoveryPort = newDiscoveryPort(true)
|
||||
}
|
||||
|
||||
return dh
|
||||
}
|
||||
|
||||
func newDiscoveryPort(includeDService bool, host *oodamdm.Host) *oodamdm.DiscoveryPort {
|
||||
func newDiscoveryPort(includeDService bool) *oodamdm.DiscoveryPort {
|
||||
dp := &oodamdm.DiscoveryPort{
|
||||
Host: host,
|
||||
FirstScanRange: 1,
|
||||
LastScanRange: 1024,
|
||||
ExcludePorts: []int{},
|
||||
IncludeTCP: true,
|
||||
IncludeUDP: true,
|
||||
}
|
||||
|
||||
if includeDService {
|
||||
dp.DiscoveryService = newDiscoveryService(nil)
|
||||
dp.DiscoveryService = newDiscoveryService()
|
||||
}
|
||||
|
||||
return dp
|
||||
}
|
||||
|
||||
func newDiscoveryService(port *oodamdm.Port) *oodamdm.DiscoveryService {
|
||||
func newDiscoveryService() *oodamdm.DiscoveryService {
|
||||
ds := &oodamdm.DiscoveryService{
|
||||
Port: port,
|
||||
IncludeServices: []string{},
|
||||
}
|
||||
return ds
|
||||
|
|
47
rpc/discovery_service.go
Normal file
47
rpc/discovery_service.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
|
||||
)
|
||||
|
||||
type DiscoveryService struct {
|
||||
}
|
||||
|
||||
func zoneString(z *model.Zone) string {
|
||||
return fmt.Sprintf("Zone (Iface[%s] Mac[%s] Network[%s] IP[%s])", z.Iface, z.Mac, z.Network, z.IP)
|
||||
}
|
||||
|
||||
func hostString(h *model.Host) string {
|
||||
return fmt.Sprintf("%s Host (Mac[%s] IP[%s] OS[%s])", zoneString(h.Zone), h.Mac, h.IP, h.OS)
|
||||
}
|
||||
|
||||
func portString(p *model.Port) string {
|
||||
return fmt.Sprintf("%s Port (Type[%s] Number[%d])", hostString(p.Host), p.PortType, p.PortNumber)
|
||||
}
|
||||
|
||||
func serviceString(s *model.Service) string {
|
||||
return fmt.Sprintf("%s Service (Type[%s] Name[%s])", portString(s.Port), s.CryptoType, s.ServiceName)
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoveredZone(z *model.Zone) error {
|
||||
log.Printf("DiscoveredZone: %s", zoneString(z))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoveredHost(h *model.Host) error {
|
||||
log.Printf("DiscoveredHost: %v", hostString(h))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoveredPort(p *model.Port) error {
|
||||
log.Printf("DiscoveredPort: %v", portString(p))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds *DiscoveryService) DiscoveredService(s *model.Service) error {
|
||||
log.Printf("DiscoveredService: %v", serviceString(s))
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user