ing
This commit is contained in:
commit
de44a6bd7e
68
.gitignore
vendored
Normal file
68
.gitignore
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
### Go template
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
vendor/
|
||||
glide.lock
|
||||
.DS_Store
|
||||
dist/
|
||||
debug
|
32
.vscode/launch.json
vendored
Normal file
32
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"remotePath": "",
|
||||
"port": 2345,
|
||||
"host": "127.0.0.1",
|
||||
"program": "${workspaceRoot}/main.go",
|
||||
"env": {},
|
||||
"args": [],
|
||||
"showLog": true
|
||||
},
|
||||
{
|
||||
"name": "File Debug",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"remotePath": "",
|
||||
"port": 2345,
|
||||
"host": "127.0.0.1",
|
||||
"program": "${fileDirname}",
|
||||
"env": {},
|
||||
"args": [],
|
||||
"showLog": true
|
||||
}
|
||||
|
||||
]
|
||||
}
|
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
|
||||
}
|
5
commons/endable_starter.go
Normal file
5
commons/endable_starter.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package commons
|
||||
|
||||
type EndableStarter interface {
|
||||
EndableStart(endded chan<- error) error
|
||||
}
|
7
commons/shutdowner.go
Normal file
7
commons/shutdowner.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package commons
|
||||
|
||||
import "context"
|
||||
|
||||
type Shutdowner interface {
|
||||
Shutdown(ctx context.Context) error
|
||||
}
|
13
discovery.go
Normal file
13
discovery.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package discovery
|
||||
|
||||
type Discoverer interface {
|
||||
}
|
||||
|
||||
type discovery struct {
|
||||
}
|
||||
|
||||
func New() Discoverer {
|
||||
d := &discovery{}
|
||||
|
||||
return d
|
||||
}
|
82
discovery/discovery.go
Normal file
82
discovery/discovery.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/discovery/types"
|
||||
)
|
||||
|
||||
type Discoverer interface {
|
||||
Discover(endded chan<- error) error
|
||||
DiscoverZone(endded chan<- error) error
|
||||
DiscoverHost(endded chan<- error) error
|
||||
DiscoverPort(endded chan<- error) error
|
||||
DiscoverService(endded chan<- error) error
|
||||
DiscoverUDPService(endded chan<- error) error
|
||||
}
|
||||
|
||||
type discovery struct {
|
||||
zd zoneDiscoverer
|
||||
hd hostDiscoverer
|
||||
pd portDiscoverer
|
||||
|
||||
endded chan<- error
|
||||
zoneEndded chan error
|
||||
hostEndded chan error
|
||||
portEndded chan error
|
||||
|
||||
zoneFound chan *types.DiscoveryZone
|
||||
}
|
||||
|
||||
func New() Discoverer {
|
||||
d := &discovery{}
|
||||
d.zd = newZoneDiscoverer()
|
||||
d.hd = newHostDiscoverer()
|
||||
d.pd = newPortDiscoverer()
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *discovery) Discover(endded chan<- error) error {
|
||||
d.endded = endded
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *discovery) DiscoverZone(endded chan<- error) error {
|
||||
d.endded = endded
|
||||
|
||||
// 1. When discoverd zone
|
||||
// 2. When occurred error
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *discovery) DiscoverHost(endded chan<- error) error {
|
||||
d.endded = endded
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *discovery) DiscoverPort(endded chan<- error) error {
|
||||
d.endded = endded
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *discovery) DiscoverService(endded chan<- error) error {
|
||||
d.endded = endded
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *discovery) DiscoverUDPService(endded chan<- error) error {
|
||||
d.endded = endded
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *discovery) Shutdown(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
31
discovery/host.go
Normal file
31
discovery/host.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/commons"
|
||||
)
|
||||
|
||||
type hostDiscoverer interface {
|
||||
commons.EndableStarter
|
||||
commons.Shutdowner
|
||||
}
|
||||
|
||||
type hostDiscovery struct {
|
||||
}
|
||||
|
||||
func newHostDiscoverer() hostDiscoverer {
|
||||
hd := &hostDiscovery{}
|
||||
|
||||
return hd
|
||||
}
|
||||
|
||||
func (hd *hostDiscovery) EndableStart(endded chan<- error) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hd *hostDiscovery) Shutdown(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
31
discovery/port.go
Normal file
31
discovery/port.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/commons"
|
||||
)
|
||||
|
||||
type portDiscoverer interface {
|
||||
commons.EndableStarter
|
||||
commons.Shutdowner
|
||||
}
|
||||
|
||||
type portDiscovery struct {
|
||||
}
|
||||
|
||||
func newPortDiscoverer() portDiscoverer {
|
||||
pd := &portDiscovery{}
|
||||
|
||||
return pd
|
||||
}
|
||||
|
||||
func (pd *portDiscovery) EndableStart(endded chan<- error) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pd *portDiscovery) Shutdown(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
31
discovery/service.go
Normal file
31
discovery/service.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/commons"
|
||||
)
|
||||
|
||||
type serviceDiscoverer interface {
|
||||
commons.EndableStarter
|
||||
commons.Shutdowner
|
||||
}
|
||||
|
||||
type serviceDiscovery struct {
|
||||
}
|
||||
|
||||
func newServiceDiscoverer() portDiscoverer {
|
||||
pd := &serviceDiscovery{}
|
||||
|
||||
return pd
|
||||
}
|
||||
|
||||
func (sd *serviceDiscovery) EndableStart(endded chan<- error) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sd *serviceDiscovery) Shutdown(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
21
discovery/types/const.go
Normal file
21
discovery/types/const.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package types
|
||||
|
||||
const (
|
||||
TYPE_TCP = "TCP"
|
||||
TYPE_UDP = "UDP"
|
||||
TYPE_TLS = "TLS"
|
||||
|
||||
SEND = "Send"
|
||||
RECV = "Recv"
|
||||
TIMEOUT = "Timeout"
|
||||
RECV_RST = "Closed"
|
||||
|
||||
SUCCESS = "Success"
|
||||
|
||||
TYPE_DISCOVERY = "DISCOVERY"
|
||||
TYPE_DETECTNETWORK = "DETECTNETWORK"
|
||||
TYPE_SENSOR = "SENSOR"
|
||||
|
||||
RANGE_TYPE_RANGE = "RANGE"
|
||||
RANGE_TYPE_TARGET = "TARGET"
|
||||
)
|
28
discovery/types/discovery.go
Normal file
28
discovery/types/discovery.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/discovery/types/timestamp"
|
||||
)
|
||||
|
||||
type DiscoveryHistory struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
StartDate timestamp.Timestamp `json:"startDate"`
|
||||
EndDate timestamp.Timestamp `json:"endDate"`
|
||||
Result bool `json:"result"`
|
||||
Zone *DiscoveryZone `json:"zone"`
|
||||
}
|
||||
|
||||
func NewDiscoveryHistory(zone *DiscoveryZone) DiscoveryHistory {
|
||||
return DiscoveryHistory{
|
||||
Zone: zone,
|
||||
StartDate: timestamp.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
type DiscoveryMgr struct {
|
||||
Stop chan bool
|
||||
DiscoveryWg *sync.WaitGroup
|
||||
Zone *DiscoveryZone
|
||||
}
|
92
discovery/types/discoveryhost.go
Normal file
92
discovery/types/discoveryhost.go
Normal file
|
@ -0,0 +1,92 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/discovery/types/timestamp"
|
||||
)
|
||||
|
||||
type DiscoveryHost struct {
|
||||
M *sync.RWMutex `json:"-"`
|
||||
Ports_ map[string]*DiscoveryPort `json:"-"`
|
||||
HostName string `json:"-"`
|
||||
PortDiscoveryTime timestamp.Timestamp `json:"-"`
|
||||
Zone *DiscoveryZone `json:"-"`
|
||||
Histories []*PortScanHistory `json:"-"`
|
||||
|
||||
FirstScanRange uint16 `json:"firstScanRange"`
|
||||
LastScanRange uint16 `json:"lastScanRange"`
|
||||
Name string `json:"name"`
|
||||
|
||||
ID int `json:"id,omitempty"`
|
||||
IP string `json:"ip"`
|
||||
Mac string `json:"mac"`
|
||||
Ports []*DiscoveryPort `json:"ports"`
|
||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||
UpdateDate timestamp.Timestamp `json:"updateDate,omitempty"`
|
||||
|
||||
Os string `json:"os,omitempty"`
|
||||
Target bool `json:"target,omitempty"`
|
||||
}
|
||||
|
||||
func (h *DiscoveryHost) SetPort(key string, value *DiscoveryPort) {
|
||||
h.M.Lock()
|
||||
defer h.M.Unlock()
|
||||
h.Ports_[key] = value
|
||||
}
|
||||
|
||||
func (h *DiscoveryHost) GetPort(key string) *DiscoveryPort {
|
||||
h.M.RLock()
|
||||
defer h.M.RUnlock()
|
||||
return h.Ports_[key]
|
||||
}
|
||||
|
||||
type HostScanHistory struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
IP string `json:"ip"`
|
||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||
SendDate timestamp.Timestamp `json:"sendDate"`
|
||||
ResultDate timestamp.Timestamp `json:"resultDate"`
|
||||
ResultType string `json:"resultType"`
|
||||
Description string `json:"description"`
|
||||
Zone *DiscoveryZone `json:"-"`
|
||||
}
|
||||
|
||||
type HostMgr struct {
|
||||
DiscoveryMgr
|
||||
ToPort chan *DiscoveryHost
|
||||
}
|
||||
|
||||
func NewHost(ip net.IP, macAddr net.HardwareAddr) *DiscoveryHost {
|
||||
host := &DiscoveryHost{
|
||||
M: new(sync.RWMutex),
|
||||
Ports_: make(map[string]*DiscoveryPort, 100),
|
||||
IP: ip.String(),
|
||||
Mac: macAddr.String(),
|
||||
CreateDate: timestamp.Now(),
|
||||
UpdateDate: timestamp.Now(),
|
||||
}
|
||||
|
||||
return host
|
||||
}
|
||||
|
||||
func NewHostHistory(ip net.IP, resultType string, des string) *HostScanHistory {
|
||||
hh := &HostScanHistory{
|
||||
IP: ip.String(),
|
||||
SendDate: timestamp.Now(),
|
||||
ResultType: resultType,
|
||||
Description: des,
|
||||
}
|
||||
|
||||
return hh
|
||||
}
|
||||
func (p *DiscoveryHost) AddHistory(h *PortScanHistory) {
|
||||
p.Histories = append(p.Histories, h)
|
||||
}
|
||||
|
||||
type PortRange struct {
|
||||
Types string
|
||||
First int
|
||||
Second int
|
||||
}
|
65
discovery/types/discoveryport.go
Normal file
65
discovery/types/discoveryport.go
Normal file
|
@ -0,0 +1,65 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/discovery/types/timestamp"
|
||||
)
|
||||
|
||||
type DiscoveryPort struct {
|
||||
Port_ string `json:"-"`
|
||||
|
||||
ID int `json:"id,omitempty"`
|
||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||
UpdateDate timestamp.Timestamp `json:"updateDate,omitempty"`
|
||||
Host *DiscoveryHost `json:"-"`
|
||||
Services []*DiscoveryService `json:"services"`
|
||||
Histories []*ServiceScanHistory `json:"-"`
|
||||
|
||||
PortType string `json:"portType"`
|
||||
Number uint16 `json:"portNumber"`
|
||||
|
||||
Target bool `json:"target,omitempty"`
|
||||
}
|
||||
|
||||
type PortScanHistory struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||
Host *DiscoveryHost `json:"-"`
|
||||
PortNumber uint16 `json:"portNumber"`
|
||||
PortType string `json:"portType"`
|
||||
DirectionType string `json:"directionType"`
|
||||
Description string `json:"description"`
|
||||
StartDate timestamp.Timestamp `json:"startDate"`
|
||||
EndDate timestamp.Timestamp `json:"endDate"`
|
||||
}
|
||||
|
||||
type PortMgr struct {
|
||||
DiscoveryMgr
|
||||
FromHost chan *DiscoveryHost
|
||||
ToService chan *DiscoveryPort
|
||||
}
|
||||
|
||||
func NewPort(port string, host *DiscoveryHost, portType string) *DiscoveryPort {
|
||||
rPort := &DiscoveryPort{Port_: port, Host: host, PortType: portType}
|
||||
i, _ := strconv.ParseUint(port, 10, 16)
|
||||
rPort.Number = uint16(i)
|
||||
return rPort
|
||||
}
|
||||
|
||||
func NewPortScanHistory(host *DiscoveryHost, port uint16, portType string, directionType string, description string) *PortScanHistory {
|
||||
rPortSH := &PortScanHistory{
|
||||
CreateDate: timestamp.Now(),
|
||||
Host: host,
|
||||
PortNumber: port,
|
||||
PortType: portType,
|
||||
DirectionType: directionType,
|
||||
Description: description,
|
||||
}
|
||||
host.AddHistory(rPortSH)
|
||||
return rPortSH
|
||||
}
|
||||
|
||||
func (p *DiscoveryPort) SetHistory(h []*ServiceScanHistory) {
|
||||
p.Histories = h
|
||||
}
|
45
discovery/types/discoveryservice.go
Normal file
45
discovery/types/discoveryservice.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"git.loafle.net/overflow/overflow_discovery/discovery/types/timestamp"
|
||||
)
|
||||
|
||||
type DiscoveryService struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||
UpdateDate timestamp.Timestamp `json:"updateDate,omitempty"`
|
||||
Port *DiscoveryPort `json:"-"`
|
||||
PortType string `json:"portType"` /*tls or normal*/
|
||||
ServiceName string `json:"serviceName"`
|
||||
|
||||
Target bool `json:"target,omitempty"`
|
||||
}
|
||||
|
||||
func NewService(ptype string, serviceName string, port *DiscoveryPort) *DiscoveryService {
|
||||
service := &DiscoveryService{PortType: ptype, ServiceName: serviceName, Port: port}
|
||||
return service
|
||||
}
|
||||
|
||||
const (
|
||||
DIRECTION_SEND = "Send"
|
||||
DIRECTION_RECV = "Recv"
|
||||
)
|
||||
|
||||
type ServiceScanHistory struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||
Port *DiscoveryPort `json:"-"`
|
||||
ServiceName string `json:"serviceName"`
|
||||
Direction string `json:"direction"`
|
||||
Packet []byte `json:"packet"`
|
||||
}
|
||||
|
||||
func NewServiceScanHistory(port *DiscoveryPort, serviceName string, direction string, packet []byte) *ServiceScanHistory {
|
||||
return &ServiceScanHistory{
|
||||
CreateDate: timestamp.Now(),
|
||||
Port: port,
|
||||
ServiceName: serviceName,
|
||||
Direction: direction,
|
||||
Packet: packet,
|
||||
}
|
||||
}
|
56
discovery/types/discoveryzone.go
Normal file
56
discovery/types/discoveryzone.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
)
|
||||
|
||||
type discoverTestZoneCallback func(host *DiscoveryZone)
|
||||
|
||||
type DiscoveryZone struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
IP string `json:"ip"`
|
||||
Netmask string `json:"mask"`
|
||||
Iface string `json:"iface"`
|
||||
Mac string `json:"mac"`
|
||||
FirstScanRange int64 `json:"firstScanRange"`
|
||||
LastScanRange int64 `json:"lastScanRange"`
|
||||
Histories []*HostScanHistory `json:"-"`
|
||||
Hosts []*DiscoveryHost `json:"hosts"`
|
||||
CurrentTypes string `json:"-"`
|
||||
|
||||
Hosts_ map[string]*DiscoveryHost `json:"-"`
|
||||
M *sync.RWMutex `json:"-"`
|
||||
}
|
||||
|
||||
func (z *DiscoveryZone) SetHost(ip string, value *DiscoveryHost) {
|
||||
z.M.Lock()
|
||||
defer z.M.Unlock()
|
||||
z.Hosts_[ip] = value
|
||||
}
|
||||
|
||||
func (z *DiscoveryZone) GetHost(ip string) (*DiscoveryHost, bool) {
|
||||
z.M.RLock()
|
||||
defer z.M.RUnlock()
|
||||
h, ok := z.Hosts_[ip]
|
||||
return h, ok
|
||||
}
|
||||
|
||||
func (p *DiscoveryZone) AddHistory(h *HostScanHistory) {
|
||||
p.Histories = append(p.Histories, h)
|
||||
}
|
||||
|
||||
func (z *DiscoveryZone) CidrString() string {
|
||||
netmask := net.IPMask(net.ParseIP(z.Netmask))
|
||||
str := z.IP + "/" + netmask.String()
|
||||
|
||||
_, ipnet, err := net.ParseCIDR(str)
|
||||
if nil != err {
|
||||
logging.Logger.Error(fmt.Sprintf("ParseCIDR: %v", err))
|
||||
}
|
||||
|
||||
return ipnet.String()
|
||||
}
|
272
discovery/types/network_test.go
Normal file
272
discovery/types/network_test.go
Normal file
|
@ -0,0 +1,272 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
//"strconv"
|
||||
//"strings"
|
||||
"testing"
|
||||
//"bytes"
|
||||
//"encoding/binary"
|
||||
//"bytes"
|
||||
//"io/ioutil"
|
||||
"git.loafle.net/overflow/overflow_discovery/discovery/types/timestamp"
|
||||
//"net/http"
|
||||
)
|
||||
|
||||
type DiscoveryZone222 struct {
|
||||
MinIp string `json:"-"`
|
||||
MaxIp string `json:"-"`
|
||||
LocalIp string `json:"ip"`
|
||||
Cidr string `json:"cidr"`
|
||||
Inter net.Interface `json:"-"`
|
||||
//Hosts map[string]*Host `json:"-"`
|
||||
}
|
||||
|
||||
func TestZone222(t *testing.T) {
|
||||
|
||||
zz := DiscoveryZone222{}
|
||||
|
||||
zz.MaxIp = "192.168.1.254"
|
||||
zz.MinIp = "192.168.1.1"
|
||||
zz.LocalIp = "192.168.1.207"
|
||||
zz.Cidr = "192.168.1.0/24"
|
||||
|
||||
jb, _ := json.Marshal(zz)
|
||||
|
||||
fmt.Println(string(jb))
|
||||
|
||||
}
|
||||
|
||||
type DiscoveryZone1 struct {
|
||||
MinIp string `json:"-"`
|
||||
MaxIp string `json:"-"`
|
||||
Ip_ string `json:"-"`
|
||||
Cidr_ string `json:"-"`
|
||||
Inter_ net.Interface `json:"-"`
|
||||
//Hosts map[string]*Host `json:"-"`
|
||||
|
||||
Ip int64 `json:"ip"`
|
||||
Cidr int64 `json:"cidr"`
|
||||
|
||||
HostScanHistories []*DiscoveryHostHistory `json:"hostScanHistories"`
|
||||
}
|
||||
|
||||
type DiscoveryHostHistory struct {
|
||||
ID int `json:"id"`
|
||||
Ip int64 `json:"ip"`
|
||||
|
||||
CreateDate timestamp.Timestamp `json:"createDate"`
|
||||
SendDate timestamp.Timestamp `json:"sendDate"`
|
||||
ResultDate timestamp.Timestamp `json:"resultDate"`
|
||||
ResultType string `json:"resultType"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func TestDiscoveryZone(t *testing.T) {
|
||||
|
||||
zones := NewZones()
|
||||
|
||||
fmt.Println(len(zones))
|
||||
fmt.Println(zones[0].LocalIp_)
|
||||
fmt.Println(zones[0].Cidr)
|
||||
|
||||
var zone DiscoveryZone = DiscoveryZone{
|
||||
MinIp_: "192.168.0.1",
|
||||
MaxIp_: "192.168.0.254",
|
||||
Cidr: "192.168.0.0/24",
|
||||
LocalIp_: "192.168.0.203",
|
||||
Inter_: net.Interface{},
|
||||
Hosts_: make(map[string]*DiscoveryHost, 255),
|
||||
Ip: 233312321,
|
||||
Cidr_: 123123321,
|
||||
}
|
||||
|
||||
var zones1 []*DiscoveryZone
|
||||
zones1 = append(zones1, &zone)
|
||||
z := NewZonesByDiscoveryZone(zones1)
|
||||
|
||||
fmt.Println(len(z))
|
||||
//for _, zone := range zones {
|
||||
// //a := inet_strton(zone.LocalIp)
|
||||
// //fmt.Println(a)
|
||||
// //
|
||||
// //str := inet_ntoa(a)
|
||||
// //
|
||||
// //fmt.Println(str)
|
||||
//
|
||||
// //aa := CidrToInt64(zone.Cidr)
|
||||
// //
|
||||
// //fmt.Println(aa)
|
||||
// //
|
||||
// //str := Int64ToCidr(aa)
|
||||
// //
|
||||
// //fmt.Println(str)
|
||||
//
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
//func CreateDHH(ip string) *DiscoveryHostHistory {
|
||||
// dhh := &DiscoveryHostHistory{}
|
||||
//
|
||||
// dhh.CreateDate = timestamp.Now()
|
||||
// dhh.SendDate = timestamp.Now()
|
||||
// dhh.ResultDate = timestamp.Now()
|
||||
// dhh.Description = "testest"
|
||||
//
|
||||
// strIp := "192.168.1."
|
||||
// strIp += ip
|
||||
// dhh.Ip = inet_strton(strIp)
|
||||
//
|
||||
// return dhh
|
||||
//}
|
||||
//
|
||||
//func TestInsertDZone(t *testing.T) {
|
||||
//
|
||||
// dz := DiscoveryZone{}
|
||||
//
|
||||
// dz.Cidr_ = "192.168.1.0/24"
|
||||
// dz.Ip_ = "192.168.1.207"
|
||||
//
|
||||
// dz.Cidr = CidrToInt64(dz.Cidr_)
|
||||
// dz.Ip = inet_strton(dz.Ip_)
|
||||
//
|
||||
// dz.HostScanHistories = append(dz.HostScanHistories, CreateDHH("103"), CreateDHH("104"), CreateDHH("105"), CreateDHH("106"))
|
||||
//
|
||||
// fmt.Println(inet_ntoa(dz.Ip))
|
||||
// fmt.Println(Int64ToCidr(dz.Cidr))
|
||||
//
|
||||
// jb, _ := json.Marshal(dz)
|
||||
//
|
||||
// fmt.Println(string(jb))
|
||||
//
|
||||
// resp, _ := http.Post("http://192.168.1.207:8080/discoveryZone", "application/json", bytes.NewBuffer(jb))
|
||||
// bb, _ := ioutil.ReadAll(resp.Body)
|
||||
//
|
||||
// ddzz := DiscoveryZone{}
|
||||
//
|
||||
// json.Unmarshal(bb, &ddzz)
|
||||
//
|
||||
// fmt.Println(ddzz)
|
||||
//
|
||||
// resp.Body.Close()
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func TestSelectDZone(t *testing.T) {
|
||||
//
|
||||
// resp, _ := http.Get("http://192.168.1.207:8080/discoveryZone/1")
|
||||
// bb, _ := ioutil.ReadAll(resp.Body)
|
||||
// ddzz := DiscoveryZone{}
|
||||
//
|
||||
// fmt.Println(string(bb))
|
||||
// json.Unmarshal(bb, &ddzz)
|
||||
//
|
||||
// fmt.Println(ddzz)
|
||||
//
|
||||
// fmt.Println(Int64ToCidr(ddzz.Cidr))
|
||||
// fmt.Println(inet_ntoa(ddzz.Ip))
|
||||
//
|
||||
// resp.Body.Close()
|
||||
//}
|
||||
//
|
||||
//func inet_ntoa(ipnr int64) net.IP {
|
||||
// var bytes [4]byte
|
||||
// bytes[0] = byte(ipnr & 0xFF)
|
||||
// bytes[1] = byte((ipnr >> 8) & 0xFF)
|
||||
// bytes[2] = byte((ipnr >> 16) & 0xFF)
|
||||
// bytes[3] = byte((ipnr >> 24) & 0xFF)
|
||||
//
|
||||
// return net.IPv4(bytes[3], bytes[2], bytes[1], bytes[0])
|
||||
//}
|
||||
//
|
||||
//// Convert net.IP to int64 , http://www.outofmemory.cn
|
||||
//func inet_aton(ipnr net.IP) int64 {
|
||||
// bits := strings.Split(ipnr.String(), ".")
|
||||
//
|
||||
// b0, _ := strconv.Atoi(bits[0])
|
||||
// b1, _ := strconv.Atoi(bits[1])
|
||||
// b2, _ := strconv.Atoi(bits[2])
|
||||
// b3, _ := strconv.Atoi(bits[3])
|
||||
//
|
||||
// var sum int64
|
||||
//
|
||||
// sum += int64(b0) << 24
|
||||
// sum += int64(b1) << 16
|
||||
// sum += int64(b2) << 8
|
||||
// sum += int64(b3)
|
||||
//
|
||||
// return sum
|
||||
//}
|
||||
//
|
||||
//func inet_strton(ipnr string) int64 {
|
||||
// bits := strings.Split(ipnr, ".")
|
||||
//
|
||||
// b0, _ := strconv.Atoi(bits[0])
|
||||
// b1, _ := strconv.Atoi(bits[1])
|
||||
// b2, _ := strconv.Atoi(bits[2])
|
||||
// b3, _ := strconv.Atoi(bits[3])
|
||||
//
|
||||
// var sum int64
|
||||
//
|
||||
// sum += int64(b0) << 24
|
||||
// sum += int64(b1) << 16
|
||||
// sum += int64(b2) << 8
|
||||
// sum += int64(b3)
|
||||
//
|
||||
// return sum
|
||||
//}
|
||||
//
|
||||
//func CidrToInt64(cidr string) int64 {
|
||||
//
|
||||
// bits := strings.Split(cidr, ".")
|
||||
//
|
||||
// b0, _ := strconv.Atoi(bits[0])
|
||||
// b1, _ := strconv.Atoi(bits[1])
|
||||
// b2, _ := strconv.Atoi(bits[2])
|
||||
// //b3, _ := strconv.Atoi(bits[3])
|
||||
//
|
||||
// masks := strings.Split(bits[3], "/")
|
||||
//
|
||||
// bb3 := masks[0]
|
||||
// bb4 := masks[1]
|
||||
//
|
||||
// b3, _ := strconv.Atoi(bb3)
|
||||
// b4, _ := strconv.Atoi(bb4)
|
||||
//
|
||||
// var sum int64
|
||||
//
|
||||
// sum += int64(b0) << 32
|
||||
// sum += int64(b1) << 24
|
||||
// sum += int64(b2) << 16
|
||||
// sum += int64(b3) << 8
|
||||
// sum += int64(b4)
|
||||
//
|
||||
// return sum
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func Int64ToCidr(cidrInt int64) string {
|
||||
//
|
||||
// c1 := cidrInt & 0xFF
|
||||
// c2 := (cidrInt >> 8) & 0xFF
|
||||
// c3 := (cidrInt >> 16) & 0xFF
|
||||
// c4 := (cidrInt >> 24) & 0xFF
|
||||
// c5 := (cidrInt >> 32) & 0xFF
|
||||
//
|
||||
// var cidr string
|
||||
//
|
||||
// cidr += strconv.FormatInt(c5, 10)
|
||||
// cidr += "."
|
||||
// cidr += strconv.FormatInt(c4, 10)
|
||||
// cidr += "."
|
||||
// cidr += strconv.FormatInt(c3, 10)
|
||||
// cidr += "."
|
||||
// cidr += strconv.FormatInt(c2, 10)
|
||||
// cidr += "/"
|
||||
// cidr += strconv.FormatInt(c1, 10)
|
||||
//
|
||||
// return cidr
|
||||
//}
|
12
discovery/types/scaninfo.go
Normal file
12
discovery/types/scaninfo.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package types
|
||||
|
||||
type ServiceScanInfo struct {
|
||||
History []*ServiceScanHistory
|
||||
Port *DiscoveryPort
|
||||
}
|
||||
|
||||
func NewServiceScanInfo(port *DiscoveryPort) *ServiceScanInfo {
|
||||
s := &ServiceScanInfo{}
|
||||
s.Port = port
|
||||
return s
|
||||
}
|
37
discovery/types/timestamp/timestamp.go
Normal file
37
discovery/types/timestamp/timestamp.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package timestamp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Timestamp time.Time
|
||||
|
||||
func (t Timestamp) MarshalJSON() ([]byte, error) {
|
||||
ts := time.Time(t).Unix()
|
||||
stamp := fmt.Sprint(ts * 1000)
|
||||
return []byte(stamp), nil
|
||||
}
|
||||
|
||||
func (t *Timestamp) UnmarshalJSON(b []byte) error {
|
||||
ts, err := strconv.Atoi(string(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = Timestamp(time.Unix(int64(ts)/1000, 0))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t Timestamp) String() string {
|
||||
return time.Time(t).String()
|
||||
}
|
||||
|
||||
func Now() Timestamp {
|
||||
return Timestamp(time.Now())
|
||||
}
|
||||
|
||||
func Date(year int, month time.Month, day int) Timestamp {
|
||||
return Timestamp(time.Date(year, month, day, 0, 0, 0, 0, time.UTC))
|
||||
}
|
31
discovery/zone.go
Normal file
31
discovery/zone.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/commons"
|
||||
)
|
||||
|
||||
type zoneDiscoverer interface {
|
||||
commons.EndableStarter
|
||||
commons.Shutdowner
|
||||
}
|
||||
|
||||
type zoneDiscovery struct {
|
||||
}
|
||||
|
||||
func newZoneDiscoverer() zoneDiscoverer {
|
||||
zd := &zoneDiscovery{}
|
||||
|
||||
return zd
|
||||
}
|
||||
|
||||
func (zd *zoneDiscovery) EndableStart(endded chan<- error) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (zd *zoneDiscovery) Shutdown(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
4
glide.yaml
Normal file
4
glide.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
package: git.loafle.net/overflow/overflow_discovery
|
||||
import:
|
||||
- package: git.loafle.net/commons_go/util
|
||||
- package: git.loafle.net/commons_go/logging
|
Loading…
Reference in New Issue
Block a user