mirror of
https://github.com/bettercap/bettercap
synced 2025-07-31 12:10:10 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
2bd768f065
commit
b868408c17
1 changed files with 32 additions and 42 deletions
|
@ -5,8 +5,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/packets"
|
"github.com/bettercap/bettercap/packets"
|
||||||
|
|
||||||
|
@ -38,58 +36,50 @@ func (mod *Prober) sendProbeMDNS(from net.IP, from_hw net.HardwareAddr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mod *Prober) mdnsProber() {
|
func (mod *Prober) mdnsListener(c chan *mdns.ServiceEntry) {
|
||||||
mod.waitGroup.Add(1)
|
mod.Debug("mdns listener started")
|
||||||
defer mod.waitGroup.Done()
|
defer mod.Debug("mdns listener stopped")
|
||||||
|
|
||||||
|
for entry := range c {
|
||||||
|
if host := mod.Session.Lan.GetByIp(entry.AddrV4.String()); host != nil {
|
||||||
|
meta := make(map[string]string)
|
||||||
|
|
||||||
|
meta["mdns:name"] = entry.Name
|
||||||
|
meta["mdns:hostname"] = entry.Host
|
||||||
|
meta["mdns:ipv4"] = entry.AddrV4.String()
|
||||||
|
|
||||||
|
if entry.AddrV6 != nil {
|
||||||
|
meta["mdns:ipv6"] = entry.AddrV6.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
meta["mdns:port"] = fmt.Sprintf("%d", entry.Port)
|
||||||
|
|
||||||
|
host.OnMeta(meta)
|
||||||
|
} else {
|
||||||
|
mod.Debug("got mdns entry for known ip %s", entry.AddrV4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mod *Prober) mdnsProber() {
|
||||||
mod.Debug("mdns prober started")
|
mod.Debug("mdns prober started")
|
||||||
defer mod.Debug("mdns.prober stopped")
|
defer mod.Debug("mdns.prober stopped")
|
||||||
|
|
||||||
|
mod.waitGroup.Add(1)
|
||||||
|
defer mod.waitGroup.Done()
|
||||||
|
|
||||||
log.SetOutput(ioutil.Discard)
|
log.SetOutput(ioutil.Discard)
|
||||||
|
|
||||||
ch := make(chan *mdns.ServiceEntry)
|
ch := make(chan *mdns.ServiceEntry)
|
||||||
wait := sync.WaitGroup{}
|
|
||||||
|
|
||||||
defer close(ch)
|
defer close(ch)
|
||||||
|
|
||||||
go func(c chan *mdns.ServiceEntry) {
|
go mod.mdnsListener(ch)
|
||||||
mod.Debug("mdns channel read started")
|
|
||||||
defer mod.Debug("mdns channel read stopped")
|
|
||||||
|
|
||||||
for entry := range c {
|
|
||||||
if host := mod.Session.Lan.GetByIp(entry.AddrV4.String()); host != nil {
|
|
||||||
meta := make(map[string]string)
|
|
||||||
|
|
||||||
meta["mdns:name"] = entry.Name
|
|
||||||
meta["mdns:hostname"] = entry.Host
|
|
||||||
meta["mdns:ipv4"] = entry.AddrV4.String()
|
|
||||||
|
|
||||||
if entry.AddrV6 != nil {
|
|
||||||
meta["mdns:ipv6"] = entry.AddrV6.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
meta["mdns:port"] = fmt.Sprintf("%d", entry.Port)
|
|
||||||
|
|
||||||
host.OnMeta(meta)
|
|
||||||
} else {
|
|
||||||
mod.Debug("got mdns entry for known ip %s", entry.AddrV4)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(ch)
|
|
||||||
|
|
||||||
for mod.Running() {
|
for mod.Running() {
|
||||||
for _, svc := range services {
|
for _, svc := range services {
|
||||||
go func(svc string, w *sync.WaitGroup) {
|
if mod.Running() {
|
||||||
w.Add(1)
|
mdns.Lookup(svc, ch)
|
||||||
defer w.Done()
|
}
|
||||||
|
|
||||||
params := mdns.DefaultParams(svc)
|
|
||||||
params.Entries = ch
|
|
||||||
params.Timeout = time.Duration(5) * time.Second
|
|
||||||
|
|
||||||
mdns.Query(params)
|
|
||||||
}(svc, &wait)
|
|
||||||
}
|
}
|
||||||
wait.Wait()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue