mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
refact: i will just comment with 'Thank you Microsoft <3'
This commit is contained in:
parent
52d7ccf3cd
commit
8a5916c685
4 changed files with 53 additions and 39 deletions
37
net/net.go
37
net/net.go
|
@ -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, '-') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue