To calculate total ipv4 number in use in us.
cd /tmp
wget http://ftp.apnic.net/stats/arin/delegated-arin-extended-20170101
(cat delegated-arin-extended-20170101 | grep -i 'US|ipv4' |cut -f 5 -d'|' | tr '\n' '+';echo 0) | bc
1608099840
It is a huge number 1608099840
.
How to calculate ipv6 number in use in us?
(cat delegated-arin-extended-20170101 | grep -i 'US|ipv6' |cut -f 5 -d'|' | tr '\n' '+';echo 0) | bc
179768
For ipv6 address in use in us as little as 179768
or it is a wrong method to calculate ?
The IPv4 delegations show the number of addresses in the delegation. IPv6 delegations show the prefix length of the delegation. If you want numbers then for each of the numbers take the length of an IPv6 address (128 bits) minus the prefix length, and calculate 2 to the power of that number to get the number of addresses in that prefix.
This should do it:
(cat delegated-arin-extended-20170101 | grep -i 'US|ipv6' | cut -f 5 -d'|' | tr '\n' '+';
echo 0) | sed -e 's/\([0-9]*\)/2^(128-\1)/g' | bc
Which gives you the more plausible number of 340285729632951762352437572028715761664
. However, that is the number of addresses delegated. It doesn't tell you much about how many are in use.