make changes to IP and gateway

This commit is contained in:
Tim Young 2017-08-28 18:37:21 -05:00
parent 31e07852cf
commit 465de0f6b0
4 changed files with 83 additions and 4 deletions

View File

@ -1181,7 +1181,7 @@ namespace EduNetworkBuilder
case HowToBreak.DeviceChangeGW:
return TraversalTechnology.gateway;
case HowToBreak.DeviceChangeIP:
return TraversalTechnology.ip_address;
return TraversalTechnology.network_interface;
case HowToBreak.EthernetBreak:
case HowToBreak.EthernetCorrupt:
return TraversalTechnology.ethernet;

View File

@ -1949,9 +1949,13 @@ namespace EduNetworkBuilder
break;
case HowToBreak.DeviceChangeGW:
//Change the IP of the gateway
if (tDevice.BreakGateway())
didit = 2;
break;
case HowToBreak.DeviceChangeIP:
//Change the IP on the outbound nic
if (tDevice.BreakIPAddress(Data))
didit = 2;
break;
case HowToBreak.EthernetBreak:
//break the link itself
@ -1994,6 +1998,8 @@ namespace EduNetworkBuilder
didit = 2;
break;
}
if (didit > 0) Console.WriteLine("Broke it:" + What.hostname + " : " + How + " : " + Data);
if (didit == 0) Console.WriteLine("Did not break it:" + What.hostname + " : " + How + " : " + Data);
return didit;
}

View File

@ -2171,7 +2171,8 @@ namespace EduNetworkBuilder
TraversalCollection.Sort((a, b) => b.Count.CompareTo(a.Count));
List<HowToBreak> BreakList = new List<HowToBreak>() { HowToBreak.PowerOff, HowToBreak.EthernetBreak,
HowToBreak.LockOutSwitch, HowToBreak.WirelessBreakKey, HowToBreak.WirelessBreakSSID, HowToBreak.VPNChangeKey };
HowToBreak.LockOutSwitch, HowToBreak.WirelessBreakKey, HowToBreak.WirelessBreakSSID, HowToBreak.VPNChangeKey,
HowToBreak.DeviceChangeIP, HowToBreak.DeviceChangeGW};
//foreach (HowToBreak one in Enum.GetValues(typeof(HowToBreak)))
// BreakList.Add(one);
count = 0;
@ -2189,12 +2190,12 @@ namespace EduNetworkBuilder
TraversalIndex = 0; //loop back to the beginning
}
//for(int i=0; i< TraversalCollection.Count; i++)
//for (int i = 0; i < TraversalCollection.Count; i++)
//{
// Console.WriteLine(i + " " + TraversalCollection[i].Source());
// Console.WriteLine(i + " " + TraversalCollection[i].Destination());
//}
//if(TraversalCollection.Count>0)
//if (TraversalCollection.Count > 0)
//{
// TraversalCollection[0].DumpPath();
//}

View File

@ -3111,6 +3111,78 @@ namespace EduNetworkBuilder
return true;
}
public bool BreakIPAddress(string nicname)
{
NetworkCard nic = NicFromName(nicname);
if (nic == null) return false;
NetworkInterface nif = nic.InterfaceFromName(nicname);
if (nif == null) return false;
IPAddress newaddress = new IPAddress("0.0.0.0");
Random rnd = NB.GetRandom();
switch(rnd.Next(8))
{
case 0:
newaddress = nif.myIP.BreakIPAddress32();
break;
case 1:
newaddress = nif.myIP.BreakIPAddressMangle();
break;
case 2:
newaddress = nif.myIP.BreakIPAddressRandom();
break;
case 3:
newaddress = nif.myIP.BreakIPAddressZero();
break;
case 4:
newaddress = nif.myIP.BreakIPNetmask32();
break;
case 5:
newaddress = nif.myIP.BreakIPNetmaskMangle();
break;
case 6:
newaddress = nif.myIP.BreakIPNetmaskRandom();
break;
case 7:
newaddress = nif.myIP.BreakIPNetmaskZero();
break;
}
if(nif.myIP != newaddress)
{
nif.myIP = newaddress;
return true;
}
return false;
}
public bool BreakGateway()
{
IPAddress newaddress = new IPAddress("0.0.0.0");
Random rnd = NB.GetRandom();
switch (rnd.Next(8))
{
case 0:
newaddress = DefaultGW.BreakIPAddress32();
break;
case 1:
newaddress = DefaultGW.BreakIPAddressMangle();
break;
case 2:
newaddress = DefaultGW.BreakIPAddressRandom();
break;
case 3:
newaddress = DefaultGW.BreakIPAddressZero();
break;
}
if (DefaultGW != newaddress)
{
DefaultGW = newaddress;
return true;
}
return false;
}
#endregion
}
}