Skip to content

Commit b6d3316

Browse files
authored
add ASN-based allow/deny recipe to README (#180)
Co-authored-by: Mzack9999 <Mzack9999@users.noreply.github.com>
1 parent 92eb466 commit b6d3316

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,47 @@ func main() {
6060
}
6161
log.Println(resp)
6262
}
63+
```
64+
65+
## ASN-based allow/deny
66+
67+
`networkpolicy` intentionally does not perform ASN→CIDR resolution itself — that responsibility belongs to [`asnmap`](https://github.com/projectdiscovery/asnmap), where BGP data, caching, and network errors are already handled. To restrict (or allow) traffic by ASN, expand it to CIDRs upstream and feed them into the existing `AllowList`/`DenyList`:
68+
69+
```go
70+
package main
71+
72+
import (
73+
"log"
74+
75+
asnmap "github.com/projectdiscovery/asnmap/libs"
76+
"github.com/projectdiscovery/networkpolicy"
77+
)
78+
79+
func main() {
80+
client, err := asnmap.NewClient()
81+
if err != nil {
82+
log.Fatal(err)
83+
}
84+
85+
var denyCIDRs []string
86+
for _, asn := range []string{"AS13335", "AS15169"} {
87+
resp, err := client.GetData(asn)
88+
if err != nil {
89+
log.Fatal(err)
90+
}
91+
nets, err := asnmap.GetCIDR(resp)
92+
if err != nil {
93+
log.Fatal(err)
94+
}
95+
for _, n := range nets {
96+
denyCIDRs = append(denyCIDRs, n.String())
97+
}
98+
}
99+
100+
np, err := networkpolicy.New(networkpolicy.Options{DenyList: denyCIDRs})
101+
if err != nil {
102+
log.Fatal(err)
103+
}
104+
_ = np
105+
}
63106
```

0 commit comments

Comments
 (0)