20
20
ipPortPattern = regexp .MustCompile (
21
21
`\b(?:\d{1,3}\.){3}\d{1,3}(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?\b` ,
22
22
)
23
+ macPattern = regexp .MustCompile (`(?i)([a-z0-9_]+_[0-9a-f]{2}(?::[0-9a-f]{2}){2}|(?:[0-9a-f]{2}[:-]){5}[0-9a-f]{2})` )
23
24
)
24
25
25
26
func root (args []string ) error {
@@ -35,6 +36,7 @@ func root(args []string) error {
35
36
flags .StringVar (& conf .Interface , "i" , "" , "The name of the network interface. Example: eth0 (Default: default interface)" )
36
37
flags .BoolVar (& conf .FullDuplex , "f" , false , "Run ARP spoofing in fullduplex mode" )
37
38
flags .BoolVar (& conf .Debug , "d" , false , "Enable debug logging" )
39
+ nocolor := flags .Bool ("nocolor" , false , "Disable colored output" )
38
40
flags .BoolFunc ("I" , "Display list of interfaces and exit." , func (flagValue string ) error {
39
41
if err := network .DisplayInterfaces (); err != nil {
40
42
fmt .Fprintf (os .Stderr , "%s: %v\n " , app , err )
@@ -53,19 +55,28 @@ func root(args []string) error {
53
55
}
54
56
conf .Gateway = & ip
55
57
}
56
- output := zerolog.ConsoleWriter {Out : os .Stdout , NoColor : false }
58
+ output := zerolog.ConsoleWriter {Out : os .Stdout , NoColor : * nocolor }
57
59
output .FormatTimestamp = func (i any ) string {
58
60
ts , _ := time .Parse (time .RFC3339 , i .(string ))
61
+ if * nocolor {
62
+ return colors .WrapBrackets (ts .Format (time .TimeOnly ))
63
+ }
59
64
return colors .Gray (colors .WrapBrackets (ts .Format (time .TimeOnly ))).String ()
60
65
}
61
66
output .FormatMessage = func (i any ) string {
62
67
if i == nil || i == "" {
63
68
return ""
64
69
}
65
70
s := i .(string )
71
+ if * nocolor {
72
+ return s
73
+ }
66
74
result := ipPortPattern .ReplaceAllStringFunc (s , func (match string ) string {
67
75
return colors .Gray (match ).String ()
68
76
})
77
+ result = macPattern .ReplaceAllStringFunc (result , func (match string ) string {
78
+ return colors .Yellow (match ).String ()
79
+ })
69
80
return result
70
81
}
71
82
logger := zerolog .New (output ).With ().Timestamp ().Logger ()
0 commit comments