@@ -18,10 +18,10 @@ import (
1818
1919var (
2020 ipPortPattern = regexp .MustCompile (
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 ` ,
21+ `(?:\[ (?:[0-9a-fA-F:.]+)\]|(?:\ 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}))?` ,
2222 )
2323 domainPattern = regexp .MustCompile (
24- `\b(?:[a-zA-Z0-9-]{1,63}\.)+(?:com|net|org|io|co|uk|ru|de|edu|gov|info|biz|dev|app|ai)(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?\b` ,
24+ `\b(?:[a-zA-Z0-9-]{1,63}\.)+(?:com|net|org|io|co|uk|ru|de|edu|gov|info|biz|dev|app|ai|tv )(?::(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4}))?\b` ,
2525 )
2626 jwtPattern = regexp .MustCompile (`\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b` )
2727 authPattern = regexp .MustCompile (
@@ -187,9 +187,9 @@ func colorizeHTTP(
187187
188188func colorizeTLS (req * layers.TLSClientHello , resp * layers.TLSServerHello , id string , nocolor bool ) string {
189189 var sb strings.Builder
190+ sb .WriteString (fmt .Sprintf ("%s " , colorizeTimestamp (time .Now (), nocolor )))
191+ sb .WriteString (id )
190192 if nocolor {
191- sb .WriteString (fmt .Sprintf ("%s " , colorizeTimestamp (time .Now (), nocolor )))
192- sb .WriteString (id )
193193 sb .WriteString (fmt .Sprintf (" %s " , req .TypeDesc ))
194194 if req .Length > 0 {
195195 sb .WriteString (fmt .Sprintf (" Len: %d" , req .Length ))
@@ -224,8 +224,6 @@ func colorizeTLS(req *layers.TLSClientHello, resp *layers.TLSServerHello, id str
224224 sb .WriteString (fmt .Sprintf (" ExtLen: %d" , resp .ExtensionLength ))
225225 }
226226 } else {
227- sb .WriteString (fmt .Sprintf ("%s " , colorizeTimestamp (time .Now (), nocolor )))
228- sb .WriteString (id )
229227 sb .WriteString (colors .Magenta (fmt .Sprintf (" %s " , req .TypeDesc )).Bold ())
230228 if req .Length > 0 {
231229 sb .WriteString (colors .BeigeBg (fmt .Sprintf (" Len: %d" , req .Length )).String ())
@@ -263,6 +261,98 @@ func colorizeTLS(req *layers.TLSClientHello, resp *layers.TLSServerHello, id str
263261 return sb .String ()
264262}
265263
264+ func colorizeRData (rec * layers.ResourceRecord ) string {
265+ var rdata string
266+ switch rd := rec .RData .(type ) {
267+ case * layers.RDataA :
268+ case * layers.RDataAAAA :
269+ rdata = fmt .Sprintf ("%s %s " , colors .LightBlue (rec .Type .Name ), colors .Gray (rd .Address .String ()))
270+ case * layers.RDataNS :
271+ rdata = fmt .Sprintf ("%s %s " , colors .LightBlue (rec .Type .Name ), colors .Gray (rd .NsdName ))
272+ case * layers.RDataCNAME :
273+ rdata = fmt .Sprintf ("%s %s " , colors .LightBlue (rec .Type .Name ), colors .Gray (rd .CName ))
274+ case * layers.RDataSOA :
275+ rdata = fmt .Sprintf ("%s %s " , colors .LightBlue (rec .Type .Name ), colors .Gray (rd .PrimaryNS ))
276+ case * layers.RDataMX :
277+ rdata = fmt .Sprintf ("%s %s %s " , colors .LightBlue (rec .Type .Name ), colors .Gray (fmt .Sprintf ("%d" , rd .Preference )), colors .Gray (rd .Exchange ))
278+ case * layers.RDataTXT :
279+ rdata = fmt .Sprintf ("%s %s " , colors .LightBlue (rec .Type .Name ), colors .Gray (rd .TxtData ))
280+ default :
281+ rdata = fmt .Sprintf ("%s " , colors .LightBlue (rec .Type .Name ))
282+ }
283+ return rdata
284+ }
285+
286+ func colorizeDNS (req , resp * layers.DNSMessage , id string , nocolor bool ) string {
287+ var sb strings.Builder
288+ sb .WriteString (fmt .Sprintf ("%s " , colorizeTimestamp (time .Now (), nocolor )))
289+ sb .WriteString (id )
290+ if nocolor {
291+ sb .WriteString (fmt .Sprintf (" DNS %s (%s) %#04x " , req .Flags .OPCodeDesc , req .Flags .QRDesc , req .TransactionID ))
292+ for _ , rec := range req .Questions {
293+ sb .WriteString (fmt .Sprintf ("%s %s " , rec .Type .Name , rec .Name ))
294+ }
295+ for _ , rec := range req .AnswerRRs {
296+ sb .WriteString (rec .Summary ())
297+ }
298+ for _ , rec := range req .AuthorityRRs {
299+ sb .WriteString (rec .Summary ())
300+ }
301+ for _ , rec := range req .AdditionalRRs {
302+ sb .WriteString (rec .Summary ())
303+ }
304+ sb .WriteString ("\n " )
305+ sb .WriteString (fmt .Sprintf ("%s " , colorizeTimestamp (time .Now (), nocolor )))
306+ sb .WriteString (id )
307+ sb .WriteString (fmt .Sprintf (" DNS %s (%s) %#04x " , resp .Flags .OPCodeDesc , resp .Flags .QRDesc , resp .TransactionID ))
308+ for _ , rec := range resp .Questions {
309+ sb .WriteString (fmt .Sprintf ("%s %s " , rec .Type .Name , rec .Name ))
310+ }
311+ for _ , rec := range resp .AnswerRRs {
312+ sb .WriteString (rec .Summary ())
313+ }
314+ for _ , rec := range resp .AuthorityRRs {
315+ sb .WriteString (rec .Summary ())
316+ }
317+ for _ , rec := range resp .AdditionalRRs {
318+ sb .WriteString (rec .Summary ())
319+ }
320+ } else {
321+ sb .WriteString (colors .Gray (fmt .Sprintf (" DNS %s (%s)" , req .Flags .OPCodeDesc , req .Flags .QRDesc )).Bold ())
322+ sb .WriteString (colors .Beige (fmt .Sprintf (" %#04x " , req .TransactionID )).String ())
323+ for _ , rec := range req .Questions {
324+ sb .WriteString (fmt .Sprintf ("%s %s " , colors .LightBlue (rec .Type .Name ), colors .Gray (rec .Name )))
325+ }
326+ for _ , rec := range req .AnswerRRs {
327+ sb .WriteString (colorizeRData (rec ))
328+ }
329+ for _ , rec := range req .AuthorityRRs {
330+ sb .WriteString (colorizeRData (rec ))
331+ }
332+ for _ , rec := range req .AdditionalRRs {
333+ sb .WriteString (colorizeRData (rec ))
334+ }
335+ sb .WriteString ("\n " )
336+ sb .WriteString (fmt .Sprintf ("%s " , colorizeTimestamp (time .Now (), nocolor )))
337+ sb .WriteString (id )
338+ sb .WriteString (colors .Blue (fmt .Sprintf (" DNS %s (%s)" , resp .Flags .OPCodeDesc , resp .Flags .QRDesc )).Bold ())
339+ sb .WriteString (colors .Beige (fmt .Sprintf (" %#04x " , resp .TransactionID )).String ())
340+ for _ , rec := range resp .Questions {
341+ sb .WriteString (fmt .Sprintf ("%s %s " , colors .LightBlue (rec .Type .Name ), colors .Gray (rec .Name )))
342+ }
343+ for _ , rec := range resp .AnswerRRs {
344+ sb .WriteString (colorizeRData (rec ))
345+ }
346+ for _ , rec := range resp .AuthorityRRs {
347+ sb .WriteString (colorizeRData (rec ))
348+ }
349+ for _ , rec := range resp .AdditionalRRs {
350+ sb .WriteString (colorizeRData (rec ))
351+ }
352+ }
353+ return sb .String ()
354+ }
355+
266356func highlightPatterns (line string , nocolor bool ) (string , bool ) {
267357 matched := false
268358
@@ -377,7 +467,7 @@ func colorizeConnections(srcRemote, srcLocal, dstRemote, dstLocal net.Addr, id s
377467}
378468
379469func colorizeConnectionsTransparent (
380- srcRemote , srcLocal , dstRemote , dstLocal net.Addr ,
470+ srcRemote , srcLocal , dstLocal , dstRemote net.Addr ,
381471 dst ,
382472 id string ,
383473 nocolor bool ,
0 commit comments