mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
new: new alias command
This commit is contained in:
parent
da185c7785
commit
a2cc2746b4
3 changed files with 36 additions and 2 deletions
|
@ -107,10 +107,15 @@ func (d *Discovery) Show(by string) error {
|
||||||
seen = core.Dim(seen)
|
seen = core.Dim(seen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name := core.Yellow(t.Hostname)
|
||||||
|
if t.Alias != "" {
|
||||||
|
name = core.Green(t.Alias)
|
||||||
|
}
|
||||||
|
|
||||||
data[i] = []string{
|
data[i] = []string{
|
||||||
t.IpAddress,
|
t.IpAddress,
|
||||||
t.HwAddress,
|
t.HwAddress,
|
||||||
core.Yellow(t.Hostname),
|
name,
|
||||||
t.Vendor,
|
t.Vendor,
|
||||||
humanize.Bytes(traffic.Sent),
|
humanize.Bytes(traffic.Sent),
|
||||||
humanize.Bytes(traffic.Received),
|
humanize.Bytes(traffic.Received),
|
||||||
|
@ -120,7 +125,7 @@ func (d *Discovery) Show(by string) error {
|
||||||
|
|
||||||
table = tablewriter.NewWriter(os.Stdout)
|
table = tablewriter.NewWriter(os.Stdout)
|
||||||
|
|
||||||
table.SetHeader([]string{"IP", "MAC", "Hostname", "Vendor", "Sent", "Recvd", "Last Seen"})
|
table.SetHeader([]string{"IP", "MAC", "Name", "Vendor", "Sent", "Recvd", "Last Seen"})
|
||||||
table.SetColWidth(80)
|
table.SetColWidth(80)
|
||||||
table.AppendBulk(data)
|
table.AppendBulk(data)
|
||||||
table.Render()
|
table.Render()
|
||||||
|
|
|
@ -22,6 +22,7 @@ type Endpoint struct {
|
||||||
IpAddressUint32 uint32 `json:"-"`
|
IpAddressUint32 uint32 `json:"-"`
|
||||||
HwAddress string `json:"mac"`
|
HwAddress string `json:"mac"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
|
Alias string `json:"alias"`
|
||||||
Vendor string `json:"vendor"`
|
Vendor string `json:"vendor"`
|
||||||
ResolvedCallback OnHostResolvedCallback `json:"-"`
|
ResolvedCallback OnHostResolvedCallback `json:"-"`
|
||||||
FirstSeen time.Time `json:"first_seen"`
|
FirstSeen time.Time `json:"first_seen"`
|
||||||
|
|
|
@ -179,6 +179,18 @@ func (s *Session) shHandler(args []string, sess *Session) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Session) aliasHandler(args []string, sess *Session) error {
|
||||||
|
mac := args[0]
|
||||||
|
alias := args[1]
|
||||||
|
|
||||||
|
if t, found := s.Targets.Targets[mac]; found == true {
|
||||||
|
t.Alias = alias
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("Could not find endpoint %s", mac)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Session) addHandler(h CommandHandler, c *readline.PrefixCompleter) {
|
func (s *Session) addHandler(h CommandHandler, c *readline.PrefixCompleter) {
|
||||||
h.Completer = c
|
h.Completer = c
|
||||||
s.CoreHandlers = append(s.CoreHandlers, h)
|
s.CoreHandlers = append(s.CoreHandlers, h)
|
||||||
|
@ -274,4 +286,20 @@ func (s *Session) registerCoreHandlers() {
|
||||||
"Execute a shell command and print its output.",
|
"Execute a shell command and print its output.",
|
||||||
s.shHandler),
|
s.shHandler),
|
||||||
readline.PcItem("!"))
|
readline.PcItem("!"))
|
||||||
|
|
||||||
|
s.addHandler(NewCommandHandler("alias MAC NAME",
|
||||||
|
"^alias\\s+([a-fA-F0-9:]{17})\\s+(.+)",
|
||||||
|
"Assign an alias to a given endpoint given its MAC address.",
|
||||||
|
s.aliasHandler),
|
||||||
|
readline.PcItem("alias", readline.PcItemDynamic(func(prefix string) []string {
|
||||||
|
prefix = strings.Trim(prefix[5:], "\t\r\n ")
|
||||||
|
macs := []string{""}
|
||||||
|
for mac, _ := range s.Targets.Targets {
|
||||||
|
if prefix == "" || strings.HasPrefix(mac, prefix) == true {
|
||||||
|
macs = append(macs, mac)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return macs
|
||||||
|
})))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue