2018-04-19 11:36:56 +00:00
|
|
|
package ipv4
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
|
|
|
occc "git.loafle.net/overflow/commons-go/core/constants"
|
2018-04-26 09:00:24 +00:00
|
|
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
2018-04-19 11:36:56 +00:00
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
)
|
|
|
|
|
2018-04-26 09:00:24 +00:00
|
|
|
func ScanService(port *ocmd.Port, ds *ocmd.DiscoveryService, 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
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-04-26 09:00:24 +00:00
|
|
|
s := &ocmd.Service{
|
2018-04-19 11:36:56 +00:00
|
|
|
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)
|
2018-04-26 09:00:24 +00:00
|
|
|
s := &ocmd.Service{
|
2018-04-19 11:36:56 +00:00
|
|
|
ServiceName: sName,
|
|
|
|
}
|
|
|
|
s.Port = port
|
|
|
|
resultChan <- s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|