Print out all IPv6 addresses

45

5

This reminds me when a few years ago someone uploaded a torrent "Hacker tool: complete list of all IP addresses". This was, of course, just a generated list of the ~4 billion IPv4 addresses, but thousands of "h4xx0rz" downloaded it. Look mum, imahacker!

This was then, but nowadays everybody has switched to IPv6. (Right?)

Your task is to write a program that prints out all IPv6 addresses.

You should write a full program that takes no input and prints IPv6 addresses, one per line, and no other output. Your program must print all 2128 possible addresses, including invalid ones. Each address must be printed exactly once. You may print the addresses in any order.

Each address may be printed in full, with 8 groups of 4 hexadecimal digits separated by colons, e.g.

2001:0db8:85a3:0000:0000:8a2e:0370:7334

You may, at your discretion, use any of the standard abbreviations from RFC 5952:

  • Leading zeros in a group may be omitted, except that 0 cannot be abbreviated further.
  • :: may be used at most once per address to abbreviate a sequence of one or more all-zero groups.
  • The hexadecimal digits may use lowercase or uppercase.

If you achieve the representation recommendation from RFC 5952 (lowercase letters only, shortest possible representation, with :: used as early as possible if there are multiple places where it can be used), you get a -20% bonus.

Due to the size of the output, your program is not expected to finish while we're sitting there. Your program may be interrupted by external means at some point (Ctrl+C, pulling out the power, …). Your program must produce output as a stream, so that after a “reasonable” wait, it will have produced some lines. Basically, building a giant string in memory only to print it at the end is not allowed. Any program that would run out of memory on a “standard” PC is disqualified. (Nonetheless, if your program was left to run for sufficiently long, it must print all IPv6 addresses and then exit.)

(If this condition is a problem for web interpreters that run the program until completion and then let you see the output, and you don't have a hosted interpreter, test your program on a smaller version of the problem, and then carefully adjust it to the full 2128.)

Your score is your program's length in bytes, multiplied by 0.8 if you get the bonus. It's code golf, so the lowest score wins.

Gilles 'SO- stop being evil'

Posted 2015-10-07T07:30:59.370

Reputation: 2 531

22This is 5.445*10¹⁵ yottabytes. To store all of that data, you need at least 15 Earth-sized datacenters containing nothing but hard drives packed in as tightly as possible. That's one big torrent..... – Kaz Wolfe – 2015-10-07T09:26:17.680

7@Mew I'm wondering how small the file would be compressed (using some generic compression like gzip) though. – SztupY – 2015-10-07T12:54:09.647

35@SztupY: apparently the output can be compressed to 25 bytes (Decompression algorithm = a Pyth interpreter, compression algorithm = posting to PPCG) From lurking on this site, it seems that Pyth is a rather generic compressed format. – Ben Voigt – 2015-10-07T16:24:43.677

3In my experience, @Gilles is a real SO heavyweight! Glad to see you bringing questions to our little PPCG corner of SO! Also fun for me to see networking-related questions. – Digital Trauma – 2015-10-07T18:08:54.943

5This reminds me of that "iterate over all possible GUIDs" question on SO. – MikeTheLiar – 2015-10-07T19:08:24.367

Should consider additional bonuses if someone wants to use the representation described in rfc 1924... or as another challenge.

– None – 2015-10-07T19:14:54.660

1Can a Verilog solution on FPGA hardware be accepted? Could the output format then be parallel ASCII? – Reinstate Monica - ζ-- – 2015-10-07T21:53:45.927

@hexafraction Um, I don't know. I guess so? I can't find an applicable meta policy. – Gilles 'SO- stop being evil' – 2015-10-07T22:12:45.047

@BenVoigt Now you just need to write a compression algorithm. :) – mbomb007 – 2015-10-08T13:32:54.880

1You know, this idea of a generated file suggests another challenge: Make a function that generates a requested byte range from a file containing all ipv6 addresses. – Random832 – 2015-10-08T13:45:33.530

1

@BenVoigt there's a long running AI/compression challenge based on handing in (their dataset compressed + your decompresser), on the idea that identifying patterns is linked to intelligence, more intelligence == better compression, and you can't cheat by handing in 1 byte + hide the data in the decompresser. CodeGolf is just like that, except with human compressers and we can offload everything possible into the interpreter. It would be a bit of a different site if we scored (code size + interpreter/compiler size).

– TessellatingHeckler – 2015-10-08T18:01:35.260

@TessellatingHeckler: Meta question related to that: http://meta.codegolf.stackexchange.com/q/7104/11335

– Ben Voigt – 2015-10-08T19:31:31.957

1What is this "IPv6" you speak of? – John Odom – 2015-10-08T20:52:07.477

Answers

5

Pyth, 21 bytes

KJ^8CdWJj\:ct.H+K=tJ4

Uses a while loop with J as the iterator variable. Initializes the maximum using 8^chr(' '). Pads by adding that initial value, converting to hex, then removing the first character.

isaacg

Posted 2015-10-07T07:30:59.370

Reputation: 39 268

That code looks like somebody sneezed on their keyboard, then tried to clean it. – darksky – 2017-12-05T01:17:29.697

@darksky That's golflangs for you :P – Esolanging Fruit – 2017-12-05T02:55:56.230

50

Python 3, 65 bytes · 0.8 = 52.0

from ipaddress import*
n=4**64
while n:n-=1;print(IPv6Address(n))

Anders Kaseorg

Posted 2015-10-07T07:30:59.370

Reputation: 29 242

7Dang python! It always has the right methods! :D – MayorMonty – 2015-10-09T01:57:02.543

ipaddress is python3 only. – None – 2016-01-28T20:05:24.790

@Hurricane996, yeah, I had been using it in Python 2 from PyPI without realizing that it only entered the standard library in Python 3. So I’ve switched this to Python 3 at the expense of one byte.

– Anders Kaseorg – 2016-02-01T18:14:42.770

@MDXF Python doesn't have ++ or -- operators – Draconis – 2017-12-05T01:52:08.183

14

Pyth, 27 25 24 bytes

Note: the code had a bug previously, fixing it saved 1 byte

J^4 64WJj\:c%"%032x"=tJ4

Prints the addresses like

ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe
ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffd
ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc
...
0000:0000:0000:0000:0000:0000:0000:0003
0000:0000:0000:0000:0000:0000:0000:0002
0000:0000:0000:0000:0000:0000:0000:0001
0000:0000:0000:0000:0000:0000:0000:0000

Previous (more complicated) version using the pad operator (also 24 bytes):

J^4 64WJj\:c.[\032.H=tJ4

Explanation

J^4 64                  set J to 2^128
WJ                     while J is not 0:
            =tJ               decrement J
    %"%032x"                 format to length-32 hex string
   c           4            split every 4 chars
j\:                        join by : and print

Pyth, 21 bytes (invalid)

jmj\:c.[\032.Hd4^4 64

This can't be run since 1) it would consume at least 2132 bytes (252 yobibytes) of memory and 2) the interpreter doesn't like it (2128 doesn't fit in ssize_t, so no lists of that size). It would print the addresses in lexicographical order. You can try out the algorithm by changing the number(s) in the end to something usable.

PurkkaKoodari

Posted 2015-10-07T07:30:59.370

Reputation: 16 699

1What about ... "Any program that would run out of memory on a “standard” PC is disqualified." ? – TessellatingHeckler – 2015-10-08T00:19:54.550

2@TessellatingHeckler The first one won't, as it runs iteratively. The second one I have clearly marked as invalid. – PurkkaKoodari – 2015-10-08T07:36:51.253

12

C (with GCC extensions), 76 bytes * 0.8 = 60.8

__uint128_t i;main(){char s[50];for(;inet_ntop(10,&i,s,49),puts(s),++i>0;);}

This uses the 128-bit integers GCC extension to simply count up from :: to ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff. inet_ntop() correctly formats each address so the -20% bonus can be claimed.

Output

Using sed to output every millionth line up to 10 million:

$ ./ipv6all | sed -n '1~1000000p;10000000q'
::
4042:f00::
8084:1e00::
c0c6:2d00::
9:3d00::
404b:4c00::
808d:5b00::
c0cf:6a00::
12:7a00::
4054:8900::
$ 

Note I am using a little-endian x86_64 machine, and that network addresses are typically always in network-order (big-endian), so the endianness is effectively swapped by using inet_ntop(). This does not matter - all addresses will still (eventually) be displayed.

Digital Trauma

Posted 2015-10-07T07:30:59.370

Reputation: 64 644

11

CJam, 36 27 bytes

G32#{(_"%032x"e%4/':*oNo}h;

-9 bytes thanks to @Dennis (I forgot that CJam has string formatting). Prints the addresses lowercase and descending.

For obvious reasons, use the Java interpreter, not the online one. You can replace G32# with something smaller for testing online though, e.g. here's the last 100.

Explanation

G32#             16^32 = 2^128. Call this n
{ ... }h;        While loop. The final ; is to pop n at the end
 (               Decrement n
 _               Copy n
 "%032x"e%       String format to hex, padded to 32 digits
 4/              Split into groups of 4
 ':*             Join with colons
 oNo             Output with newline

Sp3000

Posted 2015-10-07T07:30:59.370

Reputation: 58 729

1What's kind of interesting is that the online interpreter, beyond not being able to handle the size of course, also prints the result wrong. If you remove the loop, and only print the first value, it prints 0000:0000:0000:0000:0000:0000:ffff:ffff. Looks like the string formatting might work differently online. I confirmed that it works fine with the offline version. – Reto Koradi – 2015-10-08T15:59:28.070

n is the same as oNo in TIO. – Esolanging Fruit – 2017-04-27T19:06:01.560

8

Python 2.7, 67 bytes

n=4**64
while n:n-=1;s='%032x'%n;exec"s=s[4:]+':'+s[:4];"*7;print s

As a side effect of the method used to insert the colons, the addresses are printed with the rightmost column appearing at the left:

ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
fffe:ffff:ffff:ffff:ffff:ffff:ffff:ffff
fffc:ffff:ffff:ffff:ffff:ffff:ffff:ffff
...
0003:0000:0000:0000:0000:0000:0000:0000
0002:0000:0000:0000:0000:0000:0000:0000
0001:0000:0000:0000:0000:0000:0000:0000

xsot

Posted 2015-10-07T07:30:59.370

Reputation: 5 069

1The rotating is really neat! Also belated, but welcome from anarchy :) – Sp3000 – 2015-10-08T13:05:03.783

3If you say the rightmost column is at the left, it's printing invalid IPv6 addresses, but if the columns are in the correct places, then it's [printing] the addresses in any order. ;) – TessellatingHeckler – 2015-10-08T15:59:14.000

7

Verilog, 335

My first Verilog submission, probably could use more golfing but I don't have the energy to do so right now. c is clock, o is ASCII output. Does not qualify for formatting bonus due to zero-padding instead of abbreviating.

module b(output[0:38]o,input c);reg[127:0]a;wire[0:39]d;assign o=d[0:38];always @(posedge c) a<=a+(~(&a));genvar i,j;generate for(i=0;i<8;i=i+1) begin:q for(j=0;j<4;j=j+1) begin:r assign d[5*i+j]=a[16*i+4*j:16*i+4*j+7]>9?{4'h6,a[16*i+4*j:16*i+4*j+7]-9}:{4'h3,a[16*i+4*j:16*i+4*j+7]};end assign d[5*i+4]=8'h3A; end endgenerate endmodule

This is a simple iteration followed by some bit-twiddling to make the output ASCII. I chop the colon after the last group with a small hack. Synthesizes and appears to work for xc3s500e-4ft256-4 on ISE 13.7 lin64.

Reinstate Monica - ζ--

Posted 2015-10-07T07:30:59.370

Reputation: 288

6

C, 91-126 bytes

My original version, 119 bytes.

long a[9],i;
f(long*x){if(65536&++*x)*x=0,f(x+1);}
main(){for(;!a[8];f(a))for(i=7;i+1;i--)printf(i?"%lx:":"%lx\n",a[i]);}

Best golfed portable-ish version, 103 bytes (thanks @Dennis for some of these concepts)

long*p,a[9];
main(i){while(!a[8]){
for(i=8;i--;printf(i?"%lx:":"%lx\n",a[i]));
for(p=a;++*p>>16;*p++=0);}}

Explanation: The algorithm itself is reasonably straightforward. I used long rather than unsigned int because it's shorter. Declaring them at the file level means everything's preinitialized with zeros. The f function is a simple increment with carry that operates on the low 16 bits of each word. The loop ends when it carries into the 129th bit.

Iterating backwards for the printf means that we print the addresses in the "proper" order and also the check for printing a newline is a few characters shorter.

This does use some non-portable constructs. It's best regarded as a K&R dialect of C, since it uses implicit int return types and does not include stdio.h. And my use of long was informed by this - on most modern systems int is sufficient because it's 32 bits. This could probably run unmodified on PDP-11 Unix.

However, it can be shorter. If we assume that we can use int (either as a type wider than 16 bits, or a type of exactly 16 bits with various properties that happen to be true on many systems such as twos complement and arithmetic rollover), we can get rid of the stuff related to using long.

Version for int wider than 16 bits, 97 bytes.

a[9],*p;main(i){while(!a[8]){
for(i=8;i--;printf(i?"%x:":"%x\n",a[i]));
for(p=a;++*p>>16;*p++=0);}}

Version for 16-bit systems, 91 bytes.

a[9],*p;main(i){while(!a[8]){
for(i=8;i--;printf(i?"%x:":"%x\n",a[i]));
for(p=a;!++*p;p++);}}

Oddly enough, though, the original K&R compiler didn't actually support the declaration without int (it compiles fine, but treats the variables as external and therefore undefined at link time), so an additional three bytes are needed to change the declaration to int*p,a[9]; for a total of 94.

Also, if the assumption that it is interrupted before completing output were a hard constraint, we could remove the end check, saving five bytes.

Bonus: fully ANSI portable version, 126 bytes:

#include<stdio.h>
long*p,i,a[9];
int main(){while(!a[8]){
for(i=8;i--;printf(i?"%lx:":"%lx\n",a[i]));
for(p=a;++*p>>16;*p++=0);}}

Newlines in all versions are inserted for readability and in locations where whitespace is not required, and are excluded from the byte count, except for the newline after the #include line in the ANSI version.

All versions except the ANSI version fall through at the end of main and therefore may return a spurious exit code to the operating system.

Random832

Posted 2015-10-07T07:30:59.370

Reputation: 796

1Portability usually isn't a concern here. This works on my machine: a[9];f(int*x){if(++*x>>16)*x=f(x+1);}main(i){for(;!a[8];f(a))for(i=8;i--;)printf(i?"%x:":"%x\n",a[i]);} – Dennis – 2015-10-07T16:53:14.813

You are clearly much better at this than me. Some of those I am very surprised works ,but I should really have thought of the i-- condition check. – Random832 – 2015-10-07T17:11:08.433

When you tested this, did you run it all the way until the carry? My machine puts a random value in a[0] after rolling over in your version. – Random832 – 2015-10-07T17:16:05.593

Yes. The first 6,553,601 IP addresses are printed correctly on my machine. – Dennis – 2015-10-07T17:18:30.537

Ideone doesn't like it either, but it works on codepad: wrap in a[0] and wrap in a[1]

– Dennis – 2015-10-07T17:36:04.210

You do need the end check. Good point, I shouldn't have written “assume” — the program is supposed to be correct if not interrupted, and useful (fsvo useful) if interrupted. I've clarified the question (fortunately nobody tried to exploit this loophole), thanks. – Gilles 'SO- stop being evil' – 2015-10-07T19:29:53.160

Oops, my browser didn't show your edit before I posted my last comment... p=a;while(!++*p) -> for(p=a;!++*p;) still works though. – Dennis – 2015-10-08T14:56:45.627

5

AutoIt3, 142 231 Bytes

For $a=0 To 2^32-1
For $b=0 To 2^32-1
For $c=0 To 2^32-1
For $d=0 To 2^32-1
$s=StringFormat("%08x%08x%08x%08x",$a,$b,$c,$d)
For $j=0 To 8
ConsoleWrite(StringMid($s,$j*4+1,4)&($j<7?":":""))
Next
ConsoleWrite(@LF)
Next
Next
Next
Next

Explanation

  • For $a=0 To 2^32-1: Iterate 4 times over 0-2^32 ((2^32)^4=2^128) possible combinations.
  • $s=StringFormat("%08x%08x%08x%08x",$a,$b,$c,$d): Convert the numbers to a hexadecimal string with a length of 32 (4*32).
  • For $j=0 To 8: Iterate over all 8 sections of the string.
  • ConsoleWrite(StringMid($s,$j*4+1,4)&($j<7?":":"")): Extract the next 4 characters from the string and add a colon (:) at the end, if we haven't reached the last section, then output everything to the console
  • Next: End the inner for-loop
  • ConsoleWrite(@LF): Add a line-feed at the end of the line
  • Next: End the outer for-loops

Expected output size: (One line (39 bytes) + line-feed) (=40 bytes) * 2^128 = 1.361* 10^16 YB (yottabytes)

GiantTree

Posted 2015-10-07T07:30:59.370

Reputation: 885

Don’t you mean 4^64 - 1? – Anders Kaseorg – 2015-10-15T04:35:12.157

@AndersKaseorg apparently I need to even use 4 loops up to 2^32-1, because AutoIt can parse large values like 4^64, but can't store them for use in a loop, because integers only go up to 2^32-1 in AutoIt. – GiantTree – 2015-10-15T10:30:13.547

5

Cinnamon Gum, 16 bytes

0000000: 678b 36d0 b54c d44d 8bc5 455b 8d0c 0500  g.6..L.M..E[....                               .

Try it online. (TIO limits output)

Explanation

The g mode puts Cinnamon Gum in generate mode. The rest of the string decompresses to this regex:

[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:[0-9a-f][0-9a-f][0-9a-f][0-9a-f]

It then creates a generator of all possible strings that match the regex and iterates through it, printing out each one.

Somewhat amusingly, the golfier regex ([0-9a-f]{4,4}:){7,7}[0-9a-f]{4,4} actually compresses to a longer string than the regex above.

a spaghetto

Posted 2015-10-07T07:30:59.370

Reputation: 10 647

4

PowerShell (v4), 193 166 162 145 103 bytes

TimmyD's no-bonus version at 103 bytes:

$i=[bigint]::Pow(4,64);while($i-gt0){('{0:X32}'-f($i-=1)-replace'0(?=.{32})'-re‌​place'.{4}(?!$)','$0:')}

Previous with-bonus version at 145 * 0.8 = 116 bytes

With help from TimmyD and tomkandy, who points out that 0 -eq $false but ([bigint]0) -eq $true. So all my previous versions won't terminate.

$i=[bigint]::Pow(4,64);while($i-gt0){$i-=1;[IPAddress]::Parse((('{0:X32}'-f$i
)-replace'0(?=.{32})'-replace'.{4}(?!$)','$0:')).IPAddressToString}

Previously at 162, before some regex changes:

$i=[bigint]::Pow(4,64)
while($i){$i-=1;if(($x='{0:X32}'-f$i).Length-eq33){$x=$x.Substring(1)}
[IPAddress]::Parse(($x-replace'.{4}(?!$)','$0:')).IPAddressToString}

"A challenge where PowerShell ought to be reasonably competetive!" - me, before I tried it.

Explanation

# PowerShell (PS) has no IP address arithmetic, e.g. IP + 1
#- PS has no 128 bit integers
#- PS has no automatic bignums

# Start from the top, with the BigInteger specialised Power()
$i = [BigInt]::pow(4,64)

# Loop 4**64 through 1, work with $i-1 for ff... -> ::0
while ($i) {
    # PS has no decrement operator for bignums
    # (no using $i-- in the while loop test)
    $i-=1

    # The Net.IPAddress class can't turn a BigInteger
    # into an IPv6 address directly. And because it mashes
    # IPv4 and IPv6 into one class, there's no obvious way 
    # to make a small number always cast to an IPv6 address.
    # Format the bignum as a string of 32 hex digits.
    $x = '{0:X32}' -f $i

    # The BigInteger often formats as /33/ hex digits, 
    # with a leading zero (to avoid unintentional +/- sign bits)
    # ( https://msdn.microsoft.com/library/dd268287 )
    # So remove the leading 0, if there is one
    if (($x).Length-eq33){$x=$x.Substring(1)}

    # I can't always remove the leading zero, because it 
    # can't parse FFFFF... into an address without colons
    # and this regex replace into groups of 4 with colons
    # would go wrong at length 31. No : after the last group
    # This is still better than split/join ... because there
    # isn't a split-into-groups-of-N that I know of.
    $x = ($x -replace '.{4}(?!$)', '$1:'

    # Woo! * 0.8 bonus! 45 characters to save 38! :D
    [IPAddress]::Parse($x).IPAddressToString

}

TessellatingHeckler

Posted 2015-10-07T07:30:59.370

Reputation: 2 412

95 without bonus. Thanks to you two for introducing me to [bigint], that's rather handy (for things I oughtn't to be doing in posh in the first place...) for($g=[bigint]::pow(2,128);$g;$g-=1){'{0:X32}'-f$g-replace'(?=(.{4})+$)',':'-replace'^0+:',''} – tomkandy – 2015-10-08T17:29:16.967

Sorry should be for($g=[bigint]::pow(2,120);$g;$g-=1){'{0:X32}'-f$g-replace'(?=(.{4})+$)',':'-replace'^0*:',''} – tomkandy – 2015-10-08T17:58:22.130

for($g=[bigint]::pow(2,128);$g-gt0;$g-=1){'{0:X32}'-f$g-replace'(?=(.{4})+$)',':'-replace'^\d*:',''} Yes, the first address is wrong but it's not repeated at the end. Also note that while($i) in yours won't stop at zero - [boolean][bigint]0 evaluates as true – tomkandy – 2015-10-09T11:30:12.460

@tomkandy oh wow, I must have only ever tested the end by setting $i=5 as an int. (Complex 0 isn't $false either ... and nor is empty string. I should pay more attention to "it's not Python"). Thanks! (And this script of yours doesn't get rid of the leading 0: anymore :/ ) – TessellatingHeckler – 2015-10-09T15:37:21.223

@TessellatingHeckler Not going for the bonus is sadly 13 bytes shorter -- $i=[bigint]::Pow(4,64);while($i-gt0){('{0:X32}'-f($i-=1)-replace'0(?=.{32})'-replace'.{4}(?!$)','$0:')} at 103... – AdmBorkBork – 2015-12-14T20:58:59.873

@TimmyD wasn't much of a bonus if it didn't end up shorter afterwards, eh; I've edited it in because it's shorter, it ought to be there. – TessellatingHeckler – 2015-12-14T22:30:22.953

4

Commodore BASIC 2.0, 339 bytes

In order to get lower-case hex digits, this program is written in "shifted mode" (press <SHIFT>+<C=>)

1k=65535:a=0
2fOb=0tok:fOc=0tok:fOd=0tok:fOe=0tok:fOf=0tok:fOg=0tok:fOh=0tok
3x=a:goS6:?":";:x=b:goS6:?":";:x=c:goS6:?":";:x=d:goS6:?":";:x=e:goS6:?":";:x=f
4goS6:?":";:x=g:goS6:?":";:x=h:goS6:?
5nE:nE:nE:nE:nE:nE:nE:nE:a=a+1:ifa<65536tH2
6y=x/4096:goS7:y=x/256aN15:goS7:y=x/16aN15:goS7:y=xaN15:goS7:reT
7?mI("0123456789abcdef",y+1,1);:reT

Simply making this work on the Commodore 64 was a challenge, because of memory, screen size, data size, and other limitations. I considered implementing the abbreviated representation, but other limitations (such as the undocumented inability to use array elements as loop indices) meant it would increase the length of the program by an estimated 1000 bytes.

Line 7 is an implementation of HEX$(), which Commodore BASIC 2.0 is lacking. I can't use a DEF FN for this because those can only return numbers, not strings. Line 6 is a subroutine that applies it to a group of four digits, which would have been considerably shorter if functions could return strings.

Lines 2 and 5 are eight nested loops, implemented as seven "for" loops and a conditional goto because eight "for" loops, when combined with the two "gosubs" for printing out the address, will overflow the C64's tiny stack.

A C64 can print out about 1.2 addresses per second, for an estimated runtime of 1.3*10^31 years.

Mark

Posted 2015-10-07T07:30:59.370

Reputation: 2 099

3

AutoIt3, 137 Bytes

For $i=0 To 4^64
$s=StringFormat("%032x",$i)
For $j=0 To 7
ConsoleWrite(StringMid($s,$j*4+1,4)&($j<7?':':''))
Next
ConsoleWrite(@LF)
Next

rav_kr

Posted 2015-10-07T07:30:59.370

Reputation: 131

I know that but I'm new here :( – rav_kr – 2015-10-08T16:14:02.770

Just making sure you know. Thanks. – mbomb007 – 2015-10-08T16:58:22.267

Don’t you mean 4^64 - 1? – Anders Kaseorg – 2015-10-15T04:35:58.400

2

Ruby 75

x=->s,n{n>0?65536.times{|m|x.(s+?:*(8<=>n)+m.to_s(16),n-1)}: p(s)};x.('',8)

This is a recursive solution that takes a each prefix and finds every possible suffix. Recursively.

MegaTom

Posted 2015-10-07T07:30:59.370

Reputation: 3 787

Get shorter function definitions with lambdas: x=->s,n{...};x['',8] – Doorknob – 2015-10-07T20:53:34.703

2

Python 2, 95 bytes

def i(p=0):
 while p<4**64:print':'.join(hex(p)[2:].zfill(32)[4*s:4*s+4]for s in range(8));p+=1

Simply goes through every number from 0 to 2^128. First it converts the current number to hexadecimal string, then strips off the '0x' that that function gives. Next it adjusts the string to have 32 zeros in the front and then breaks it up into groups of four. Finally it joins the groups of four with colons, prints that out and adds 1 to the current number. Has the added bonus that you can start it at any value if you give it one, but no input is needed.

Status

Posted 2015-10-07T07:30:59.370

Reputation: 995

If your answer is a function, you don't need to call it :) – Beta Decay – 2015-10-09T17:30:52.003

@BetaDecay Then that was my misunderstanding. Fixed! Thanks. – Status – 2015-10-09T18:08:31.577

2

Haskell 111

s[]=[[]]
s(a:b)=[y:z|z<-s b,y<-a]
r=replicate
main=mapM putStrLn$s$tail$concat$r 8$":":r 4"0123456789abcdef"

With my own sequence function s it no longer leaks memory, but does not feel golfed any more.

Franky

Posted 2015-10-07T07:30:59.370

Reputation: 131

How do you compile it so that it doesn't run out of memory? With my ghc v7.10.2 and std. compile options it leaks memory. – nimi – 2015-10-09T19:08:12.287

2

CBM BASIC v7.0 (166 characters)

a=65535
fOi=0toa:fOj=0toa:fOk=0toa:fOl=0toa:fOm=0toa:fOn=0toa:fOo=0toa:fOp=0toa:?hE(i)":"hE(j)":"hE(k)":"hE(l)":"hE(m)":"hE(n)":"hE(o)":"hE(p):nE:nE:nE:nE:nE:nE:nE:nE

Mark's answer is for the Commodore 64's BASIC 2.0, which lacks a built-in command for printing numbers in hexadecimal. However, thanks to the HEX$() function in BASIC 7.0, the Commodore 128 version is much shorter. It doesn't fit on a single logical line (which on the C128 is limited to 160 characters) but can still be entered as two separate lines in direct mode.

Psychonaut

Posted 2015-10-07T07:30:59.370

Reputation: 233

It looks like you're missing half your loops. An IPv6 address is 128 bits, not 64 bits. – Mark – 2015-10-16T18:21:21.153

@Mark: Thanks for pointing this out! I've fixed the problem. – Psychonaut – 2015-10-18T08:52:08.173

0

Tcl 341 318 301

proc ip6 {p c} {
    set s %x:%x:%x:%x:%x:%x:%x:%x
    set p [scan $p $s]
    while {[set d 7]} {
        $c [format [string map {x 04x} $s] {*}$p]
        while {[set i [lindex $p $d]]==0xFFFF} {
            lset p $d 0
            if {!$d} return
            incr d -1
        }
        lset p $d [incr i]
    }
}
ip6 fFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0000 puts

wolfhammer

Posted 2015-10-07T07:30:59.370

Reputation: 1 219