Link speed for windows network fingerprinting - tests
This commit is contained in:
parent
679fefc155
commit
b6b3e24541
|
@ -19,16 +19,21 @@ func (f *NetworkFingerprint) linkSpeed(device string) int {
|
|||
}
|
||||
|
||||
output := strings.TrimSpace(string(outBytes))
|
||||
args := strings.Split(output, " ")
|
||||
|
||||
return f.parseLinkSpeed(output)
|
||||
}
|
||||
|
||||
func (f *NetworkFingerprint) parseLinkSpeed(commandOutput string) int {
|
||||
args := strings.Split(commandOutput, " ")
|
||||
if len(args) != 2 {
|
||||
f.logger.Printf("[WARN] fingerprint.network: Couldn't split LinkSpeed (%s)", output)
|
||||
f.logger.Printf("[WARN] fingerprint.network: Couldn't split LinkSpeed (%s)", commandOutput)
|
||||
return 0
|
||||
}
|
||||
|
||||
unit := strings.Replace(args[1], "\r\n", "", -1)
|
||||
value, err := strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
f.logger.Printf("[WARN] fingerprint.network: Unable to parse LinkSpeed value (%s)", output)
|
||||
f.logger.Printf("[WARN] fingerprint.network: Unable to parse LinkSpeed value (%s)", commandOutput)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
30
client/fingerprint/network_windows_test.go
Normal file
30
client/fingerprint/network_windows_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package fingerprint
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNetworkFingerPrint_linkspeed_parse(t *testing.T) {
|
||||
f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &DefaultNetworkInterfaceDetector{}}
|
||||
|
||||
var outputTests = []struct {
|
||||
in string
|
||||
out int
|
||||
}{
|
||||
{"10 Mbps", 10},
|
||||
{"2 bps", 0},
|
||||
{"1 Gbps", 1000},
|
||||
{"2Mbps", 0},
|
||||
{"1000 Kbps", 1},
|
||||
{"1 Kbps", 0},
|
||||
{"0 Mbps", 0},
|
||||
{"2 2 Mbps", 0},
|
||||
{"a Mbps", 0},
|
||||
{"1 Tbps", 0},
|
||||
}
|
||||
|
||||
for _, ot := range outputTests {
|
||||
out := f.parseLinkSpeed(ot.in)
|
||||
if out != ot.out {
|
||||
t.Errorf("parseLinkSpeed(%s) => %d, should be %d", ot.in, out, ot.out)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue