simple for loop script to build out ipv6 subnet Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of simple for loop script to build out ipv6 subnet without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am trying to use nmap to scan a /119 IPv6 network. (512 addresses). Before I do this I want to generate a file that will populate all of the ip addresses in that range. The network info is as follows:

network 2607:f4a0:3:0:250:56ff:feac:3c00
Prefix length   119
network range   2607:f4a0:0003:0000:0250:56ff:feac:3c00-
                2607:f4a0:0003:0000:0250:56ff:feac:3dff

So I set my script up like this:

[root@ns1 ~]# for i in {1..512}; do printf "2607:f4a0:3:0:250:56ff:feac:3c00%xn" $i >> ipv6.txt; done

What I expect to see in the file are 512 addresses that are within the range above. However what I see instead is this:

2607:f4a0:3:0:250:56ff:feac:3c001
2607:f4a0:3:0:250:56ff:feac:3c002
2607:f4a0:3:0:250:56ff:feac:3c003
2607:f4a0:3:0:250:56ff:feac:3c004
2607:f4a0:3:0:250:56ff:feac:3c005
2607:f4a0:3:0:250:56ff:feac:3c006
2607:f4a0:3:0:250:56ff:feac:3c007
2607:f4a0:3:0:250:56ff:feac:3c008
2607:f4a0:3:0:250:56ff:feac:3c009
2607:f4a0:3:0:250:56ff:feac:3c00a
2607:f4a0:3:0:250:56ff:feac:3c00b
2607:f4a0:3:0:250:56ff:feac:3c00c
2607:f4a0:3:0:250:56ff:feac:3c00d
2607:f4a0:3:0:250:56ff:feac:3c00e
2607:f4a0:3:0:250:56ff:feac:3c00f
2607:f4a0:3:0:250:56ff:feac:3c0010
2607:f4a0:3:0:250:56ff:feac:3c0011
2607:f4a0:3:0:250:56ff:feac:3c0012
2607:f4a0:3:0:250:56ff:feac:3c0013
2607:f4a0:3:0:250:56ff:feac:3c0014
2607:f4a0:3:0:250:56ff:feac:3c0015
2607:f4a0:3:0:250:56ff:feac:3c0016
2607:f4a0:3:0:250:56ff:feac:3c0017
2607:f4a0:3:0:250:56ff:feac:3c0018
2607:f4a0:3:0:250:56ff:feac:3c0019
2607:f4a0:3:0:250:56ff:feac:3c001a
2607:f4a0:3:0:250:56ff:feac:3c001b
2607:f4a0:3:0:250:56ff:feac:3c001c

When I go to run nmap I get errors:

nmap -Pn -sT -p 22 -6 -iL ipv6.txt > ipv6up

Errors:

Failed to resolve given IPv6 hostname/IP:    2607:f4a0:3:0:250:56ff:feac:3c00200.  Note that you can't use '/mask' or   '[1-4,7,100-]' style ranges for IPv6.

How can I fix this?

Answer

for i in {15360..15871}; do printf "2607:f4a0:3:0:250:56ff:feac:%.4xn" $i; done

Output:

2607:f4a0:3:0:250:56ff:feac:3c00
2607:f4a0:3:0:250:56ff:feac:3c01
2607:f4a0:3:0:250:56ff:feac:3c02
2607:f4a0:3:0:250:56ff:feac:3c03
.
.
.
2607:f4a0:3:0:250:56ff:feac:3dfd
2607:f4a0:3:0:250:56ff:feac:3dfe
2607:f4a0:3:0:250:56ff:feac:3dff
We are here to answer your question about simple for loop script to build out ipv6 subnet - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji