How to sort list of Ip Addresses using c#
This might look as a hack, but it does exactly what you need:
var unsortedIps =
new[]
{
"192.168.1.4",
"192.168.1.5",
"192.168.2.1",
"10.152.16.23",
"69.52.220.44"
};
var sortedIps = unsortedIps
.Select(Version.Parse)
.OrderBy(arg => arg)
.Select(arg => arg.ToString())
.ToList();
You can convert each IP address into an integer like so ...
69.52.220.44 =>
69 * 255 * 255 * 255 +
52 * 255 * 255 +
220 * 255 +
44
Then sort by the integer representation.