make IPaddress breakage tools

This commit is contained in:
Tim Young 2017-08-28 18:13:34 -05:00
parent 537bb31835
commit 31e07852cf

View File

@ -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<string> toRandomize = new List<string>(parts);
List<string> randomized = new List<string>();
string neworder = "";
while (!done)
{
randomized = NB.Randomize<string>(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