Generate hexadecimal

Hello
I'm working on a script to list all ipv6 from given address
so I've run this script which create hex part of ipv6

STR2=159
END2=200
SUM2=`expr $END2 - $STR2`
for ((i=STR2;i<=END2;++i)); do
x=$( printf "%x" $i ) ; echo $x
echo -e "::"$x >> netpart.txt
done

output is :

::9f
::a0
::a1
::a2
::a3
::a4
::a5
etc. 

there are a billion ip between 0000:0000:0000:0000 AND ffff:ffff:ffff:ffff like:

0000:0000:0000:0000
0000:0000:0000:0095
0000:0000:0000:0096

How can I list all of them?

---------- Post updated at 04:31 PM ---------- Previous update was at 04:07 PM ----------

mm let me explain more clear
0000:0000:0000:0095 has 4 part and each part max number is 9999 so the last number will be 9999:9999:9999:9999

How can I read number from user like 100000 and then calculate and echo all number after 0000:0000:0000:0095

Something like:

0000:0000:0000:0095
0000:0000:0000:0096
....
0000:0000:0000:9999
0000:0000:0001:0000
0000:0000:0001:0001
0000:0000:0001:0002
....
etc

You could try this:

STR2=159
END2=200
for ((i=STR2; i<=END2; i++))
do
    printf -v HEX "%016x" $i
    printf "%s:%s:%s:%s\n" ${HEX:0:4} ${HEX:4:4} ${HEX:8:4} ${HEX:12:4}
done

But be aware you will run into an issue with IPs greater than "7fff:ffff:ffff:ffff" as bash uses signed 64-bit integers. The highest order bit is a sign bit and so the integer representation of these values will be a negative number:

  -1 = ffff:ffff:ffff:ffff
  -2 = ffff:ffff:ffff:fffe
...
-256 = ffff:ffff:ffff:ff00
...
-9223372036854775807 = 8000:0000:000:0001
-9223372036854775808 = 8000:0000:000:0000
 9223372036854775807 = 7fff:ffff:ffff:ffff
 9223372036854775806 = 7fff:ffff:ffff:fffe
...

Your question is a bit difficult to understand and answer as you're talking IPv6 and hexadecimal, but you're showing numbers and samples that don't comply.

  • IPv6 uses 128 bit addresses, split into 8 subparts of 16bit each, represented in what is known as "colon-hexadecimal".
  • depending on where you come from, a billion is 1E9 or 1E12, respectively. A hex number consisting of 16 sequential "F"s (equ. 4 subparts) is roughly 1,8E19, so way beyond that.
  • in hexadecimal, "FFFF" would be the last representable number in four digits, not "each part max number is 9999". So the difference between 0x10000 and 0x95 would be 0xFF6B (65387), leading to quite unwieldy an output file.

Considering these implications, Chubler_XL's proposal handles the situation of non-IPv6 perfectly well:

STR2=65530
END2=65540
for ((i=STR2; i<=END2; i++)); do     printf -v HEX "%016X" $i;     printf "%s:%s:%s:%s\n" ${HEX:0:4} ${HEX:4:4} ${HEX:8:4} ${HEX:12:4}; done
0000:0000:0000:FFFA
0000:0000:0000:FFFB
0000:0000:0000:FFFC
0000:0000:0000:FFFD
0000:0000:0000:FFFE
0000:0000:0000:FFFF
0000:0000:0001:0000
0000:0000:0001:0001
0000:0000:0001:0002
0000:0000:0001:0003
0000:0000:0001:0004