DEV Community


Posted on • Updated on

Shortest C# program to display IP addresses in a range.

Just for fun, I tried to write the shortest code to take two IP addresses from the command line and list the IP addresses between them.

This doesn't check for errors or broadcast addresses or anything of the like, hence the "fun" part.

If you can make this shorter please show your skills in the comments.

This is written in C# 10 with top level statements enabled, so it is a complete programs.

uint p(string b) => BitConverter.ToUInt32(b.Split(".").Reverse().Select(byte.Parse).ToArray());

for (var ip = p(args[0]); ip <= p(args[1]); ip++)
    Console.WriteLine(string.Join(".", BitConverter.GetBytes(ip).Reverse()));
Enter fullscreen mode Exit fullscreen mode

Top comments (0)