Tags

, ,

1. Go to ftp://ftp.apnic.net/pub/stats/apnic/

Download the latest delegated-apnic* file. This file contnet all the IP address and ASN delegated by APNIC to it’s region. Open the file and remove the comments and ASN part.

2. Get those IP which are allocated to BD.

# more delegated-apnic-20130506 | grep BD > bdip.txt

Now you have bdip.txt file having following content:

apnic|BD|ipv4|27.0.96.0|8192|20110302|allocated
apnic|BD|ipv4|27.131.12.0|1024|20100421|allocated
apnic|BD|ipv4|27.147.128.0|32768|20100331|allocated
apnic|BD|ipv4|42.0.4.0|1024|20110317|allocated
apnic|BD|ipv4|42.99.116.0|1024|20110322|allocated
apnic|BD|ipv4|49.0.32.0|8192|20101027|allocated
apnic|BD|ipv4|58.65.224.0|2048|20060607|allocated
apnic|BD|ipv4|58.97.128.0|32768|20110107|allocated
apnic|BD|ipv4|58.145.184.0|2048|20060615|allocated
apnic|BD|ipv4|58.147.168.0|2048|20060613|allocated

3. Filed no 4 has the IP address and field no 5 has the no of host. Fetch the IP address and no of host and replace the | by /.

# awk -F”|” ‘{ print $4″/”$5}’ bdip.txt > bdip2.txt

4. File bdip2.txt look like:

27.0.96.0/8192
27.131.12.0/1024
27.147.128.0/32768
42.0.4.0/1024
42.99.116.0/1024
49.0.32.0/8192
58.65.224.0/2048
58.97.128.0/32768
58.145.184.0/2048
58.147.168.0/2048

5. Now we have to replace the no of host part to CIDR subnet mask. No of host represent following CIDR:

No of Host->CIDR
256->24
512->23
1024->22
2048->21
4096->20
8192->19
16384->18
32768->17
65536->16
131072->15

6. You can manually change this No of Host to CIDR using bash find replace command:

# bdip2.txt
# :%s/256/24

What it does is replace all 256 by 24. You can do the same for other subnet.

If you are an advance shell script coder, you can write a shell script and replace at once. I am not that good in bash, so I do it manually.

Now you can use it for filtering based on IP/SUBNET. I basically use it for zone based DNS configuration.

If you need to add ; at the end of each line, do the following:

# sed ‘s/$/;/’ bdip2.txt