networking - Golang - check if IP address is in a network -
given:
- a network address a: (
172.17.0.0/16
) - and ip address host b: (
172.17.0.2/16
)
how can if b in a?
all addresses string variables in following form: [ip address in dot-decimal notation]/[subnet mask]
. should try manipulating strings (initial thoughts). there different path?
here same question python: "how can check if ip in network in python". approach go: go/golang check ip address in range
the go net package includes following functions:
- parsecidr: takes string representing ip/mask , returns ip , ipnet
- ipnet.contains: checks whether ip in network
this should cover needs.
Comments
Post a Comment