mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 13:33:21 -07:00
refact: renamed package net to network to avoid collision with golang net package.
This commit is contained in:
parent
21236c257e
commit
48d27f274a
28 changed files with 298 additions and 298 deletions
59
network/net_windows.go
Normal file
59
network/net_windows.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/google/gopacket/pcap"
|
||||
)
|
||||
|
||||
// only matches gateway lines
|
||||
var IPv4RouteParser = regexp.MustCompile("^.+\\s+.+\\s+\\d+\\s+([0-9\\.]+/\\d+)\\s+\\d+\\s+([0-9\\.]+).*$")
|
||||
var IPv4RouteTokens = 3
|
||||
var IPv4RouteCmd = "netsh"
|
||||
var IPv4RouteCmdOpts = []string{"interface", "ipv4", "show", "route"}
|
||||
|
||||
func IPv4RouteIsGateway(ifname string, tokens []string, f func(gateway string) (*Endpoint, error)) (*Endpoint, error) {
|
||||
// TODO check if the subnet is the same as iface ?
|
||||
// subnet := tokens[1]
|
||||
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
|
||||
*
|
||||
* FIXME: Just to be clear *THIS IS SHIT*. Please someone test, find a more
|
||||
* elegant solution and refactor ... i'm seriously tired of this.
|
||||
*/
|
||||
|
||||
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