overflow_discovery/discovery/ipv4/service.go

47 lines
1.3 KiB
Go
Raw Normal View History

2017-11-22 10:04:04 +00:00
package ipv4
import (
"fmt"
2017-12-04 09:37:39 +00:00
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"
2017-11-22 10:04:04 +00:00
"github.com/google/gopacket/layers"
)
2017-12-04 09:37:39 +00:00
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
}
2017-11-22 10:04:04 +00:00
switch port.PortType {
2017-12-04 09:37:39 +00:00
case oocmd.PortTypeTCP:
2017-11-22 10:04:04 +00:00
if !scanServiceTCP(port, ds, resultChan, errChan, stopChan) {
2017-12-04 09:37:39 +00:00
if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
s := &discoveryM.Service{
2017-11-22 10:04:04 +00:00
ServiceName: sName,
}
s.Port = port
resultChan <- s
}
}
2017-12-04 09:37:39 +00:00
case oocmd.PortTypeUDP:
2017-11-22 10:04:04 +00:00
if !scanServiceUDP(port, ds, resultChan, errChan, stopChan) {
2017-12-04 09:37:39 +00:00
if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
s := &discoveryM.Service{
2017-11-22 10:04:04 +00:00
ServiceName: sName,
}
s.Port = port
resultChan <- s
}
}
}
}