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