49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package ipv4
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
|
ocmm "git.loafle.net/overflow/commons-go/model/meta"
|
|
"github.com/google/gopacket/layers"
|
|
)
|
|
|
|
func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
|
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
|
if err != nil {
|
|
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
|
return
|
|
}
|
|
|
|
switch ocmm.ToMetaPortTypeEnum(port.MetaPortType) {
|
|
case ocmm.MetaPortTypeEnumTCP:
|
|
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)
|
|
s := &ocmd.Service{
|
|
Name: sName,
|
|
DiscoveredDate: occu.NowPtr(),
|
|
Port: port,
|
|
}
|
|
resultChan <- s
|
|
}
|
|
}
|
|
|
|
case ocmm.MetaPortTypeEnumUDP:
|
|
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)
|
|
s := &ocmd.Service{
|
|
Name: sName,
|
|
DiscoveredDate: occu.NowPtr(),
|
|
Port: port,
|
|
}
|
|
resultChan <- s
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|