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)
|
||||
}
|
||||
|
||||
name := core.Yellow(t.Hostname)
|
||||
if t.Alias != "" {
|
||||
name = core.Green(t.Alias)
|
||||
}
|
||||
|
||||
data[i] = []string{
|
||||
t.IpAddress,
|
||||
t.HwAddress,
|
||||
core.Yellow(t.Hostname),
|
||||
name,
|
||||
t.Vendor,
|
||||
humanize.Bytes(traffic.Sent),
|
||||
humanize.Bytes(traffic.Received),
|
||||
|
@ -120,7 +125,7 @@ func (d *Discovery) Show(by string) error {
|
|||
|
||||
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.AppendBulk(data)
|
||||
table.Render()
|
||||
|
|
|
@ -22,6 +22,7 @@ type Endpoint struct {
|
|||
IpAddressUint32 uint32 `json:"-"`
|
||||
HwAddress string `json:"mac"`
|
||||
Hostname string `json:"hostname"`
|
||||
Alias string `json:"alias"`
|
||||
Vendor string `json:"vendor"`
|
||||
ResolvedCallback OnHostResolvedCallback `json:"-"`
|
||||
FirstSeen time.Time `json:"first_seen"`
|
||||
|
|
|
@ -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