refact: i will just comment with 'Thank you Microsoft <3'

This commit is contained in:
evilsocket 2018-02-07 23:10:57 +01:00
commit 8a5916c685
4 changed files with 53 additions and 39 deletions

View file

@ -4,51 +4,14 @@ import (
"fmt"
"net"
"regexp"
"runtime"
"strconv"
"strings"
"github.com/evilsocket/bettercap-ng/core"
"github.com/google/gopacket/pcap"
)
const MonitorModeAddress = "0.0.0.0"
func areTheSame(iface net.Interface, piface pcap.Interface) bool {
if addrs, err := iface.Addrs(); err == nil {
for _, ia := range addrs {
for _, ib := range piface.Addresses {
if ia.String() == ib.IP.String() || strings.HasPrefix(ia.String(), ib.IP.String()) {
return true
}
}
}
}
return false
}
func getInterfaceName(iface net.Interface) string {
// all normal operating systems
if runtime.GOOS != "windows" {
return iface.Name
}
// Microsoft Windows
devs, err := pcap.FindAllDevs()
if err != nil {
return iface.Name
}
for _, dev := range devs {
if areTheSame(iface, dev) {
return dev.Name
}
}
return iface.Name
}
func NormalizeMac(mac string) string {
var parts []string
if strings.ContainsRune(mac, '-') {