// 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 Program { private static int Str2Int(string s) { return IPAddress.NetworkToHostOrder(BitConverter.ToInt32(IPAddress.Parse(s).GetAddressBytes(), 0)); } private static string Int2Str(int v) { return (new IPAddress(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(v)))).ToString(); } public delegate void NetHandler(string net, string start, string end, string bcst); public static void Test(string net, string mask, NetHandler nh) { int inet = Str2Int(net); int imask = Str2Int(mask); int i = inet; while(i <= (inet | 0x000000FF)) { nh(Int2Str(i), Int2Str(i + 1), Int2Str(i - 1 + ~imask), Int2Str(i + ~imask)); i += (1 + ~imask); } } private static void Print(string net, string start, string end, string bcst) { Console.WriteLine(net + " " + start + " " + end + " " + bcst); } public static void Main(string[] args) { Test("15.20.10.0", "255.255.255.192", Print); } } }