overflow_discovery/discovery/ipv4/service.go
crusader 9527a68c71 ing
2017-12-04 18:37:39 +09:00

47 lines
1.3 KiB
Go

package ipv4
import (
"fmt"
cuej "git.loafle.net/commons_go/util/encoding/json"
oocmd "git.loafle.net/overflow/overflow_commons_go/modules/discovery"
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
"github.com/google/gopacket/layers"
)
func ScanService(port *discoveryM.Port, ds *discoveryM.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 oocmd.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 := &discoveryM.Service{
ServiceName: sName,
}
s.Port = port
resultChan <- s
}
}
case oocmd.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 := &discoveryM.Service{
ServiceName: sName,
}
s.Port = port
resultChan <- s
}
}
}
}