mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -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
|
@ -2,6 +2,7 @@ package net
|
|||
|
||||
import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// only matches gateway lines
|
||||
|
@ -16,3 +17,37 @@ func IPv4RouteIsGateway(ifname string, tokens []string, f func(gateway string) (
|
|||
gateway := tokens[2]
|
||||
return f(gateway)
|
||||
}
|
||||
|
||||
/*
|
||||
* net.Interface does not have the correct name on Windows and pcap.Interface
|
||||
* does not have the hardware address for some reason ... so this is what I
|
||||
* had to do in Windows ... tnx Microsoft <3
|
||||
*/
|
||||
|
||||
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 {
|
||||
devs, err := pcap.FindAllDevs()
|
||||
if err != nil {
|
||||
return iface.Name
|
||||
}
|
||||
|
||||
for _, dev := range devs {
|
||||
if areTheSame(iface, dev) {
|
||||
return dev.Name
|
||||
}
|
||||
}
|
||||
|
||||
return iface.Name
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue