I'm receiving from an external Application (which I can't change) and creating Strings from them:
string startAddress = "192.168.10.10";
string endAddress = "192.168.10.20";
What I would like to achieve is to put every IP between those into an array or something similar so I can loop through them.
Here is a dirty way of managing this as I know the IPs should not leave the 192.168.10.0/24 subnet.
string startAddress = networkRange.from;
string endAddress = networkRange.to;
string startAddressPartial = startAddress.Substring(startAddress.LastIndexOf('.') + 1);
string lastAddressPartial = endAddress.Substring(endAddress.LastIndexOf('.') + 1);
int startAddressInt = Int32.Parse(startAddressPartial);
int lastAddressInt = Int32.Parse(lastAddressPartial);
var networkIPArray = Enumerable.Range(startAddressInt, lastAddressInt).ToArray();
foreach (int ip in networkIPArray)
{
string ipOk = "192.168.10." + ip;
Console.WriteLine(ipOk);
}
Thanks,