mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
adding networking interfaces addresses for api.rest
This commit is contained in:
parent
72370dec58
commit
f8dda1e8e9
1 changed files with 48 additions and 12 deletions
|
@ -12,12 +12,27 @@ import (
|
||||||
"github.com/bettercap/bettercap/packets"
|
"github.com/bettercap/bettercap/packets"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var flagNames = []string{
|
||||||
|
"UP",
|
||||||
|
"BROADCAST",
|
||||||
|
"LOOPBACK",
|
||||||
|
"POINT2POINT",
|
||||||
|
"MULTICAST",
|
||||||
|
}
|
||||||
|
|
||||||
|
type addrJSON struct {
|
||||||
|
Address string `json:"address"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
type ifaceJSON struct {
|
type ifaceJSON struct {
|
||||||
Index int `json:"index"`
|
Index int `json:"index"`
|
||||||
MTU int `json:"mtu"`
|
MTU int `json:"mtu"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
MAC string `json:"mac"`
|
MAC string `json:"mac"`
|
||||||
Flags net.Flags `json:"flags"`
|
Vendor string `json:"vendor"`
|
||||||
|
Flags []string `json:"flags"`
|
||||||
|
Addresses []addrJSON `json:"addresses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type sessionJSON struct {
|
type sessionJSON struct {
|
||||||
|
@ -71,13 +86,34 @@ func (s *Session) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, iface := range ifaces {
|
for _, iface := range ifaces {
|
||||||
doc.Interfaces = append(doc.Interfaces, ifaceJSON{
|
mac := network.NormalizeMac(iface.HardwareAddr.String())
|
||||||
Index: iface.Index,
|
|
||||||
MTU: iface.MTU,
|
ij := ifaceJSON{
|
||||||
Name: iface.Name,
|
Index: iface.Index,
|
||||||
MAC: iface.HardwareAddr.String(),
|
MTU: iface.MTU,
|
||||||
Flags: iface.Flags,
|
Name: iface.Name,
|
||||||
})
|
MAC: mac,
|
||||||
|
Vendor: network.ManufLookup(mac),
|
||||||
|
Flags: make([]string, 0),
|
||||||
|
Addresses: make([]addrJSON, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
if addrs, err := iface.Addrs(); err == nil {
|
||||||
|
for _, addr := range addrs {
|
||||||
|
ij.Addresses = append(ij.Addresses, addrJSON{
|
||||||
|
Address: addr.String(),
|
||||||
|
Type: addr.Network(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for bit, name := range flagNames {
|
||||||
|
if iface.Flags&(1<<uint(bit)) != 0 {
|
||||||
|
ij.Flags = append(ij.Flags, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.Interfaces = append(doc.Interfaces, ij)
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.Marshal(doc)
|
return json.Marshal(doc)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue