A class that can parse IP domain (e.g. 192.168.0.0/16)

71 Views Asked by At

I am writing a simple script in D that needs to interface with command-line network programs that use IP domain addresses (e.g. 10.0.14.0/24).

Is there any ready parser existing for that in D?

Something, that can validate a domain and break it into elements.

1

There are 1 best solutions below

1
Adam D. Ruppe On BEST ANSWER

I dug up my old code and formatted it a bit for github. It is probably buggy though:

https://github.com/adamdruppe/arsd/blob/master/cidr.d

You use it like

import cidr;
import std.stdio;
void main() {
     auto block = IPv4Block("192.168.1.0/24");
     foreach(address; block) writeln(address);
}

and stuff like that.