diff --git a/EduNetworkBuilder/IPAddress.cs b/EduNetworkBuilder/IPAddress.cs index fb21f63..01e0ea9 100644 --- a/EduNetworkBuilder/IPAddress.cs +++ b/EduNetworkBuilder/IPAddress.cs @@ -259,6 +259,91 @@ namespace EduNetworkBuilder if (tMask == _mask) return true; return false; } + + + #region Break an IP + public string GenRandomIPOrMask() + { + Random rnd = NB.GetRandom(); + int mask1 = rnd.Next(256); + int mask2 = rnd.Next(256); + int mask3 = rnd.Next(256); + int mask4 = rnd.Next(256); + string answer = mask1 + "." + mask2 + "." + mask3 + "." + mask4; + return answer; + } + + public string randomizeOctects(string original) + { + string[] parts = original.Split('.'); + bool done = false; + List toRandomize = new List(parts); + List randomized = new List(); + string neworder = ""; + while (!done) + { + randomized = NB.Randomize(toRandomize); + neworder = string.Join(".", randomized.ToArray()); + if(neworder != original) + done = true; + } + return neworder; + } + + public IPAddress BreakIPNetmaskZero() + { + IPAddress one = new IPAddress(GetIPString, "0.0.0.0", myType); + return one; + } + public IPAddress BreakIPNetmask32() + { + IPAddress one = new IPAddress(GetIPString, "255.255.255.255", myType); + return one; + } + public IPAddress BreakIPNetmaskRandom() + { + string randomMask = ""; + do + { + randomMask = GenRandomIPOrMask(); + } while (randomMask == GetMaskString); + IPAddress one = new IPAddress(GetIPString, randomMask, myType); + return one; + } + public IPAddress BreakIPNetmaskMangle() + { + string newmask = randomizeOctects(GetMaskString); + IPAddress one = new IPAddress(GetIPString, newmask, myType); + return one; + } + + public IPAddress BreakIPAddressZero() + { + IPAddress one = new IPAddress("0.0.0.0", GetIPString, myType); + return one; + } + public IPAddress BreakIPAddress32() + { + IPAddress one = new IPAddress("255.255.255.255", GetIPString, myType); + return one; + } + public IPAddress BreakIPAddressRandom() + { + string randomIP = ""; + do + { + randomIP = GenRandomIPOrMask(); + } while (randomIP == GetMaskString); + IPAddress one = new IPAddress(randomIP, GetMaskString, myType); + return one; + } + public IPAddress BreakIPAddressMangle() + { + string newip = randomizeOctects(GetMaskString); + IPAddress one = new IPAddress(newip, GetMaskString, myType); + return one; + } + #endregion } public static class IpHelpers