Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate over IP addresses

Tags:

c#

.net

Let's say I have two IP addresses (in .NET, the System.Net.IPAddress class). How can I iterate over all the IP addresses between two given addresses?

For example, let one address be 192.168.1.1 and the other 192.168.2.3. I want to somehow iterate over all the addresses in between and print them to the console.

Thank you.

like image 447
Ove Avatar asked Nov 26 '22 12:11

Ove


1 Answers

In the end I ended up using the approach provided in this answer.

It's a little more complicated but it works well without using deprecated properties. It converts IP addresses to uints, increments them, then converts them back.

like image 156
Ove Avatar answered Dec 16 '22 14:12

Ove