Merge pull request #27 from miegl/master

frontend: optional ASN resolution using whois
This commit is contained in:
Yuhui Xu 2021-07-31 17:02:25 +08:00 committed by GitHub
commit 2e0cb131ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,8 @@ import (
) )
func getASNRepresentation(asn string) string { func getASNRepresentation(asn string) string {
if setting.dnsInterface != "" {
// get ASN representation using DNS
records, err := net.LookupTXT(fmt.Sprintf("AS%s.%s", asn, setting.dnsInterface)) records, err := net.LookupTXT(fmt.Sprintf("AS%s.%s", asn, setting.dnsInterface))
if err != nil { if err != nil {
// DNS query failed, only use ASN as output // DNS query failed, only use ASN as output
@ -19,6 +21,20 @@ func getASNRepresentation(asn string) string {
result = strings.Join(resultSplit[1:], "\\n") result = strings.Join(resultSplit[1:], "\\n")
} }
return fmt.Sprintf("AS%s\\n%s", asn, result) return fmt.Sprintf("AS%s\\n%s", asn, result)
} else {
// get ASN representation using WHOIS
records := whois(fmt.Sprintf("AS%s", asn))
recordsSplit := strings.Split(records, "\n")
result := "\\n"
for _, line := range recordsSplit {
if strings.Contains(line, "as-name:") || strings.Contains(line, "ASName:") {
result = result + strings.TrimSpace(strings.SplitN(line, ":", 2)[1])
} else if strings.Contains(line, "descr:") {
result = result + "\\n" + strings.TrimSpace(strings.SplitN(line, ":", 2)[1])
}
}
return fmt.Sprintf("AS%s%s", asn, result)
}
} }
func birdRouteToGraphviz(servers []string, responses []string, target string) string { func birdRouteToGraphviz(servers []string, responses []string, target string) string {