mirror of
https://github.com/bettercap/bettercap
synced 2025-07-11 15:46:59 -07:00
refact: minor refactoring of net.recon module
This commit is contained in:
parent
f1f9ca4ef0
commit
dd2fd0f30f
1 changed files with 49 additions and 41 deletions
|
@ -65,32 +65,7 @@ func (d Discovery) OnSessionEnded(s *session.Session) {
|
|||
}
|
||||
}
|
||||
|
||||
func (d *Discovery) Start() error {
|
||||
if d.Running() == false {
|
||||
d.SetRunning(true)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Duration(d.refresh) * time.Second):
|
||||
var err error
|
||||
|
||||
if d.current, err = net.ArpUpdate(d.Session.Interface.Name()); err != nil {
|
||||
d.Session.Events.Log(session.ERROR, "%s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
var new net.ArpTable = make(net.ArpTable)
|
||||
var rem net.ArpTable = make(net.ArpTable)
|
||||
|
||||
if d.before != nil {
|
||||
new = net.ArpDiff(d.current, d.before)
|
||||
rem = net.ArpDiff(d.before, d.current)
|
||||
} else {
|
||||
new = d.current
|
||||
}
|
||||
|
||||
if len(new) > 0 || len(rem) > 0 {
|
||||
func (d *Discovery) checkShared(new net.ArpTable) {
|
||||
n_gw_shared := 0
|
||||
for ip, mac := range new {
|
||||
if ip != d.Session.Gateway.IpAddress && mac == d.Session.Gateway.HwAddress {
|
||||
|
@ -109,8 +84,23 @@ func (d *Discovery) Start() error {
|
|||
b = ""
|
||||
}
|
||||
|
||||
d.Session.Events.Log(session.WARNING, "WARNING: Found %d endpoint%s which share%s the same MAC of the gateway (%s), there're might be some IP isolation going on, skipping.", n_gw_shared, a, b, d.Session.Gateway.HwAddress)
|
||||
d.Session.Events.Log(session.WARNING, "Found %d endpoint%s which share%s the same MAC of the gateway (%s), there're might be some IP isolation going on, skipping.", n_gw_shared, a, b, d.Session.Gateway.HwAddress)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Discovery) runDiff() {
|
||||
var new net.ArpTable = make(net.ArpTable)
|
||||
var rem net.ArpTable = make(net.ArpTable)
|
||||
|
||||
if d.before != nil {
|
||||
new = net.ArpDiff(d.current, d.before)
|
||||
rem = net.ArpDiff(d.before, d.current)
|
||||
} else {
|
||||
new = d.current
|
||||
}
|
||||
|
||||
if len(new) > 0 || len(rem) > 0 {
|
||||
d.checkShared(new)
|
||||
|
||||
// refresh target pool
|
||||
for ip, mac := range rem {
|
||||
|
@ -121,6 +111,24 @@ func (d *Discovery) Start() error {
|
|||
d.Session.Targets.AddIfNotExist(ip, mac)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Discovery) Start() error {
|
||||
if d.Running() == false {
|
||||
d.SetRunning(true)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Duration(d.refresh) * time.Second):
|
||||
var err error
|
||||
|
||||
if d.current, err = net.ArpUpdate(d.Session.Interface.Name()); err != nil {
|
||||
d.Session.Events.Log(session.ERROR, "%s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
d.runDiff()
|
||||
|
||||
d.before = d.current
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue