Add asinfo package for AS number information lookups
- Created pkg/asinfo with embedded AS data from ipverse/asn-info - Provides fast lookups by ASN with GetDescription() and GetHandle() - Includes Search() functionality for finding AS by name/handle - Added asinfo-gen tool to fetch and convert CSV data to JSON - Added 'make asupdate' target to refresh AS data - Embedded JSON data contains 130k+ AS entries - Added comprehensive tests and examples
This commit is contained in:
29
pkg/asinfo/example_test.go
Normal file
29
pkg/asinfo/example_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package asinfo_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.eeqj.de/sneak/routewatch/pkg/asinfo"
|
||||
)
|
||||
|
||||
func ExampleGet() {
|
||||
info, ok := asinfo.Get(15169)
|
||||
if ok {
|
||||
fmt.Printf("AS%d: %s - %s\n", info.ASN, info.Handle, info.Description)
|
||||
}
|
||||
// Output: AS15169: GOOGLE - Google LLC
|
||||
}
|
||||
|
||||
func ExampleGetDescription() {
|
||||
desc := asinfo.GetDescription(13335)
|
||||
fmt.Println(desc)
|
||||
// Output: Cloudflare, Inc.
|
||||
}
|
||||
|
||||
func ExampleSearch() {
|
||||
results := asinfo.Search("MIT-GATEWAY")
|
||||
for _, info := range results {
|
||||
fmt.Printf("AS%d: %s - %s\n", info.ASN, info.Handle, info.Description)
|
||||
}
|
||||
// Output: AS3: MIT-GATEWAYS - Massachusetts Institute of Technology
|
||||
}
|
||||
Reference in New Issue
Block a user