// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Net; namespace E { public class MainClass { public static void PrintAllAddresses(string ip, string mask) { byte[] iptmp = IPAddress.Parse(ip).GetAddressBytes(); Array.Reverse(iptmp); int ip2 = BitConverter.ToInt32(iptmp, 0); byte[] masktmp = IPAddress.Parse(mask).GetAddressBytes(); Array.Reverse(masktmp); int mask2 = BitConverter.ToInt32(masktmp, 0); int start = (ip2 & mask2) + 1; int end = ip2 | (~mask2) - 1; for(int i = start; i <= end; i++) { byte[] tmp = BitConverter.GetBytes(i); Array.Reverse(tmp); IPAddress adr = IPAddress.Parse(tmp[0] + "." + tmp[1] + "." + tmp[2] + "." + tmp[3]); Console.WriteLine(adr); } } public static void Main(string[] args) { PrintAllAddresses("192.168.1.10", "255.255.255.0"); } } }