mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
new: new alias command
This commit is contained in:
parent
da185c7785
commit
a2cc2746b4
3 changed files with 36 additions and 2 deletions
|
@ -179,6 +179,18 @@ func (s *Session) shHandler(args []string, sess *Session) error {
|
|||
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) {
|
||||
h.Completer = c
|
||||
s.CoreHandlers = append(s.CoreHandlers, h)
|
||||
|
@ -274,4 +286,20 @@ func (s *Session) registerCoreHandlers() {
|
|||
"Execute a shell command and print its output.",
|
||||
s.shHandler),
|
||||
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