fix(printable): actually hide sections if requested (#164)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #164 Reviewed-by: grumbulon <grumbulon@grumbulon.xyz>
This commit is contained in:
parent
11ebd2c69f
commit
185a79e1c2
1 changed files with 107 additions and 99 deletions
|
@ -277,103 +277,29 @@ func MakePrintable(res util.Response, opts *util.Options) (*Message, error) {
|
|||
}
|
||||
}
|
||||
|
||||
for _, question := range msg.Question {
|
||||
var name string
|
||||
if opts.Display.UcodeTranslate {
|
||||
name, err = idna.ToUnicode(question.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("punycode to unicode: %w", err)
|
||||
}
|
||||
} else {
|
||||
name = question.Name
|
||||
}
|
||||
|
||||
ret.Question = append(ret.Question, Question{
|
||||
Name: name,
|
||||
Type: dns.TypeToString[question.Qtype],
|
||||
Class: dns.ClassToString[question.Qclass],
|
||||
})
|
||||
}
|
||||
|
||||
for _, answer := range msg.Answer {
|
||||
temp := strings.Split(answer.String(), "\t")
|
||||
|
||||
var (
|
||||
ttl string
|
||||
name string
|
||||
)
|
||||
|
||||
if opts.Display.TTL {
|
||||
if opts.Display.HumanTTL {
|
||||
ttl = (time.Duration(answer.Header().Ttl) * time.Second).String()
|
||||
if opts.Display.Question {
|
||||
for _, question := range msg.Question {
|
||||
var name string
|
||||
if opts.Display.UcodeTranslate {
|
||||
name, err = idna.ToUnicode(question.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("punycode to unicode: %w", err)
|
||||
}
|
||||
} else {
|
||||
ttl = strconv.Itoa(int(answer.Header().Ttl))
|
||||
name = question.Name
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Display.UcodeTranslate {
|
||||
name, err = idna.ToUnicode(answer.Header().Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("punycode to unicode: %w", err)
|
||||
}
|
||||
} else {
|
||||
name = answer.Header().Name
|
||||
ret.Question = append(ret.Question, Question{
|
||||
Name: name,
|
||||
Type: dns.TypeToString[question.Qtype],
|
||||
Class: dns.ClassToString[question.Qclass],
|
||||
})
|
||||
}
|
||||
|
||||
ret.Answer = append(ret.Answer, Answer{
|
||||
RRHeader: RRHeader{
|
||||
Name: name,
|
||||
Type: dns.TypeToString[answer.Header().Rrtype],
|
||||
Class: dns.ClassToString[answer.Header().Class],
|
||||
Rdlength: answer.Header().Rdlength,
|
||||
TTL: ttl,
|
||||
},
|
||||
Value: temp[len(temp)-1],
|
||||
})
|
||||
}
|
||||
|
||||
for _, ns := range msg.Ns {
|
||||
temp := strings.Split(ns.String(), "\t")
|
||||
|
||||
var (
|
||||
ttl string
|
||||
name string
|
||||
)
|
||||
|
||||
if opts.Display.TTL {
|
||||
if opts.Display.HumanTTL {
|
||||
ttl = (time.Duration(ns.Header().Ttl) * time.Second).String()
|
||||
} else {
|
||||
ttl = strconv.Itoa(int(ns.Header().Ttl))
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Display.UcodeTranslate {
|
||||
name, err = idna.ToUnicode(ns.Header().Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("punycode to unicode: %w", err)
|
||||
}
|
||||
} else {
|
||||
name = ns.Header().Name
|
||||
}
|
||||
|
||||
ret.Authority = append(ret.Authority, Answer{
|
||||
RRHeader: RRHeader{
|
||||
Name: name,
|
||||
Type: dns.TypeToString[ns.Header().Rrtype],
|
||||
Class: dns.ClassToString[ns.Header().Class],
|
||||
Rdlength: ns.Header().Rdlength,
|
||||
TTL: ttl,
|
||||
},
|
||||
Value: temp[len(temp)-1],
|
||||
})
|
||||
}
|
||||
|
||||
for _, additional := range msg.Extra {
|
||||
if additional.Header().Rrtype == dns.StringToType["OPT"] {
|
||||
continue
|
||||
} else {
|
||||
temp := strings.Split(additional.String(), "\t")
|
||||
if opts.Display.Answer {
|
||||
for _, answer := range msg.Answer {
|
||||
temp := strings.Split(answer.String(), "\t")
|
||||
|
||||
var (
|
||||
ttl string
|
||||
|
@ -382,27 +308,27 @@ func MakePrintable(res util.Response, opts *util.Options) (*Message, error) {
|
|||
|
||||
if opts.Display.TTL {
|
||||
if opts.Display.HumanTTL {
|
||||
ttl = (time.Duration(additional.Header().Ttl) * time.Second).String()
|
||||
ttl = (time.Duration(answer.Header().Ttl) * time.Second).String()
|
||||
} else {
|
||||
ttl = strconv.Itoa(int(additional.Header().Ttl))
|
||||
ttl = strconv.Itoa(int(answer.Header().Ttl))
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Display.UcodeTranslate {
|
||||
name, err = idna.ToUnicode(additional.Header().Name)
|
||||
name, err = idna.ToUnicode(answer.Header().Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("punycode to unicode: %w", err)
|
||||
}
|
||||
} else {
|
||||
name = additional.Header().Name
|
||||
name = answer.Header().Name
|
||||
}
|
||||
|
||||
ret.Additional = append(ret.Additional, Answer{
|
||||
ret.Answer = append(ret.Answer, Answer{
|
||||
RRHeader: RRHeader{
|
||||
Name: name,
|
||||
Type: dns.TypeToString[additional.Header().Rrtype],
|
||||
Class: dns.ClassToString[additional.Header().Class],
|
||||
Rdlength: additional.Header().Rdlength,
|
||||
Type: dns.TypeToString[answer.Header().Rrtype],
|
||||
Class: dns.ClassToString[answer.Header().Class],
|
||||
Rdlength: answer.Header().Rdlength,
|
||||
TTL: ttl,
|
||||
},
|
||||
Value: temp[len(temp)-1],
|
||||
|
@ -410,6 +336,88 @@ func MakePrintable(res util.Response, opts *util.Options) (*Message, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if opts.Display.Authority {
|
||||
for _, ns := range msg.Ns {
|
||||
temp := strings.Split(ns.String(), "\t")
|
||||
|
||||
var (
|
||||
ttl string
|
||||
name string
|
||||
)
|
||||
|
||||
if opts.Display.TTL {
|
||||
if opts.Display.HumanTTL {
|
||||
ttl = (time.Duration(ns.Header().Ttl) * time.Second).String()
|
||||
} else {
|
||||
ttl = strconv.Itoa(int(ns.Header().Ttl))
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Display.UcodeTranslate {
|
||||
name, err = idna.ToUnicode(ns.Header().Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("punycode to unicode: %w", err)
|
||||
}
|
||||
} else {
|
||||
name = ns.Header().Name
|
||||
}
|
||||
|
||||
ret.Authority = append(ret.Authority, Answer{
|
||||
RRHeader: RRHeader{
|
||||
Name: name,
|
||||
Type: dns.TypeToString[ns.Header().Rrtype],
|
||||
Class: dns.ClassToString[ns.Header().Class],
|
||||
Rdlength: ns.Header().Rdlength,
|
||||
TTL: ttl,
|
||||
},
|
||||
Value: temp[len(temp)-1],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Display.Additional {
|
||||
for _, additional := range msg.Extra {
|
||||
if additional.Header().Rrtype == dns.StringToType["OPT"] {
|
||||
continue
|
||||
} else {
|
||||
temp := strings.Split(additional.String(), "\t")
|
||||
|
||||
var (
|
||||
ttl string
|
||||
name string
|
||||
)
|
||||
|
||||
if opts.Display.TTL {
|
||||
if opts.Display.HumanTTL {
|
||||
ttl = (time.Duration(additional.Header().Ttl) * time.Second).String()
|
||||
} else {
|
||||
ttl = strconv.Itoa(int(additional.Header().Ttl))
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Display.UcodeTranslate {
|
||||
name, err = idna.ToUnicode(additional.Header().Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("punycode to unicode: %w", err)
|
||||
}
|
||||
} else {
|
||||
name = additional.Header().Name
|
||||
}
|
||||
|
||||
ret.Additional = append(ret.Additional, Answer{
|
||||
RRHeader: RRHeader{
|
||||
Name: name,
|
||||
Type: dns.TypeToString[additional.Header().Rrtype],
|
||||
Class: dns.ClassToString[additional.Header().Class],
|
||||
Rdlength: additional.Header().Rdlength,
|
||||
TTL: ttl,
|
||||
},
|
||||
Value: temp[len(temp)-1],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Display.Statistics {
|
||||
ret.Statistics = Statistics{
|
||||
RTT: res.RTT.String(),
|
||||
|
|
Loading…
Reference in a new issue