2018-04-19 11:36:56 +00:00
|
|
|
package ipv4
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
2018-05-11 02:44:47 +00:00
|
|
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
2018-04-26 09:00:24 +00:00
|
|
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
2018-06-13 10:20:14 +00:00
|
|
|
ocmm "git.loafle.net/overflow/commons-go/model/meta"
|
2018-04-19 11:36:56 +00:00
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
)
|
|
|
|
|
2018-04-27 16:20:01 +00:00
|
|
|
func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
2018-04-19 11:36:56 +00:00
|
|
|
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
|
|
|
if err != nil {
|
|
|
|
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-13 10:20:14 +00:00
|
|
|
switch ocmm.ToMetaPortTypeEnum(port.MetaPortType) {
|
|
|
|
case ocmm.MetaPortTypeEnumTCP:
|
2018-04-19 11:36:56 +00:00
|
|
|
if !scanServiceTCP(port, ds, resultChan, errChan, stopChan) {
|
|
|
|
if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
|
|
|
|
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
2018-04-26 09:00:24 +00:00
|
|
|
s := &ocmd.Service{
|
2018-06-13 10:20:14 +00:00
|
|
|
Name: sName,
|
2018-05-11 02:44:47 +00:00
|
|
|
DiscoveredDate: occu.NowPtr(),
|
|
|
|
Port: port,
|
2018-04-19 11:36:56 +00:00
|
|
|
}
|
|
|
|
resultChan <- s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 10:20:14 +00:00
|
|
|
case ocmm.MetaPortTypeEnumUDP:
|
2018-04-19 11:36:56 +00:00
|
|
|
if !scanServiceUDP(port, ds, resultChan, errChan, stopChan) {
|
|
|
|
if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
|
|
|
|
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
2018-04-26 09:00:24 +00:00
|
|
|
s := &ocmd.Service{
|
2018-06-13 10:20:14 +00:00
|
|
|
Name: sName,
|
2018-05-11 02:44:47 +00:00
|
|
|
DiscoveredDate: occu.NowPtr(),
|
|
|
|
Port: port,
|
2018-04-19 11:36:56 +00:00
|
|
|
}
|
|
|
|
resultChan <- s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|