47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
|
package ipv4
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
||
|
occc "git.loafle.net/overflow/commons-go/core/constants"
|
||
|
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
||
|
"github.com/google/gopacket/layers"
|
||
|
)
|
||
|
|
||
|
func ScanService(port *ocdm.Port, ds *ocdm.DiscoveryService, 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 port.PortType {
|
||
|
case occc.PortTypeTCP:
|
||
|
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 := &ocdm.Service{
|
||
|
ServiceName: sName,
|
||
|
}
|
||
|
s.Port = port
|
||
|
resultChan <- s
|
||
|
}
|
||
|
}
|
||
|
|
||
|
case occc.PortTypeUDP:
|
||
|
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 := &ocdm.Service{
|
||
|
ServiceName: sName,
|
||
|
}
|
||
|
s.Port = port
|
||
|
resultChan <- s
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|