| 1 | package net_sniff |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net" |
| 6 | |
| 7 | "github.com/bettercap/bettercap/session" |
| 8 | |
| 9 | "github.com/evilsocket/islazy/tui" |
| 10 | "github.com/google/gopacket/layers" |
| 11 | ) |
| 12 | |
| 13 | func vIP(ip net.IP) string { |
| 14 | if session.I.Interface.IP.Equal(ip) { |
| 15 | return tui.Dim("local") |
| 16 | } else if session.I.Gateway.IP.Equal(ip) { |
| 17 | return "gateway" |
| 18 | } |
| 19 | |
| 20 | address := ip.String() |
| 21 | host := session.I.Lan.GetByIp(address) |
| 22 | if host != nil { |
| 23 | if host.Hostname != "" { |
| 24 | return host.Hostname |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | return address |
| 29 | } |
| 30 | |
| 31 | func vPort(p interface{}) string { |
| 32 | sp := fmt.Sprintf("%d", p) |
| 33 | if tcp, ok := p.(layers.TCPPort); ok { |
| 34 | if name, found := layers.TCPPortNames[tcp]; found { |
| 35 | sp = tui.Yellow(name) |
| 36 | } |
| 37 | } else if udp, ok := p.(layers.UDPPort); ok { |
| 38 | if name, found := layers.UDPPortNames[udp]; found { |
| 39 | sp = tui.Yellow(name) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return sp |
| 44 | } |
| 45 | |
| 46 | var maxUrlSize = 80 |
| 47 | |
| 48 | func vURL(u string) string { |
| 49 | ul := len(u) |
| 50 | if ul > maxUrlSize { |
| 51 | u = fmt.Sprintf("%s...", u[0:maxUrlSize-3]) |
| 52 | } |
| 53 | return u |
| 54 | } |