2020 ipPortPattern = regexp .MustCompile (
2121 `\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` ,
2222 )
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})` )
2324)
2425
2526func root (args []string ) error {
@@ -35,6 +36,7 @@ func root(args []string) error {
3536 flags .StringVar (& conf .Interface , "i" , "" , "The name of the network interface. Example: eth0 (Default: default interface)" )
3637 flags .BoolVar (& conf .FullDuplex , "f" , false , "Run ARP spoofing in fullduplex mode" )
3738 flags .BoolVar (& conf .Debug , "d" , false , "Enable debug logging" )
39+ nocolor := flags .Bool ("nocolor" , false , "Disable colored output" )
3840 flags .BoolFunc ("I" , "Display list of interfaces and exit." , func (flagValue string ) error {
3941 if err := network .DisplayInterfaces (); err != nil {
4042 fmt .Fprintf (os .Stderr , "%s: %v\n " , app , err )
@@ -53,19 +55,28 @@ func root(args []string) error {
5355 }
5456 conf .Gateway = & ip
5557 }
56- output := zerolog.ConsoleWriter {Out : os .Stdout , NoColor : false }
58+ output := zerolog.ConsoleWriter {Out : os .Stdout , NoColor : * nocolor }
5759 output .FormatTimestamp = func (i any ) string {
5860 ts , _ := time .Parse (time .RFC3339 , i .(string ))
61+ if * nocolor {
62+ return colors .WrapBrackets (ts .Format (time .TimeOnly ))
63+ }
5964 return colors .Gray (colors .WrapBrackets (ts .Format (time .TimeOnly ))).String ()
6065 }
6166 output .FormatMessage = func (i any ) string {
6267 if i == nil || i == "" {
6368 return ""
6469 }
6570 s := i .(string )
71+ if * nocolor {
72+ return s
73+ }
6674 result := ipPortPattern .ReplaceAllStringFunc (s , func (match string ) string {
6775 return colors .Gray (match ).String ()
6876 })
77+ result = macPattern .ReplaceAllStringFunc (result , func (match string ) string {
78+ return colors .Yellow (match ).String ()
79+ })
6980 return result
7081 }
7182 logger := zerolog .New (output ).With ().Timestamp ().Logger ()
0 commit comments