What is the easiest way using common linux tools to check if a bunch of ip addresses belongs to given network? I just need a number of how many of given addresses belongs to given subnet. Lets say network is 192.16.55.40/27 and addresses is 192.16.55.45, 192.16.55.115, 88.87.45.8, 192.16.55.37, 192.16.55.60 and 192.16.55.210..
相关问题
- Is shmid returned by shmget() unique across proces
- IPAddress.[Try]Parse parses 192.168 to 192.0.0.168
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Error building gcc 4.8.3 from source: libstdc++.so
I needed this to, and decided to create a short script. I requires sed and bash. I'd call them both common linux tools.
Edit: Script too long to paste, apparently. You can find it here: http://folk.ntnu.no/olechrt/netaddr
$ cat ips
$ cat ips | netaddr 192.16.55.40/27
And finally, for the count you requested:
$ cat ips | netaddr 192.16.55.40/27 | wc -l
I'm not sure whether you consider Ruby as a "common linux tool" but it has a nice module called
IPAddr
that has a method calledinclude?
for that.