DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Antidisestablishmentarianism
Antidisestablishmentarianism

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.

These are written in C# 10 with top level statements enabled, so they are 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)

DEV runs on 100% open source code known as Forem.

Β 
Contribute to the codebase or host your own.
Β 
Check these out! πŸ‘‡