Compare commits

...

25 Commits

Author SHA1 Message Date
Tim Young fdc3877e4f Fix some spelling mistakes 2019-05-15 14:38:07 -05:00
Tim Young 93f0c6e4a3 Allow ping/arp/traceroute to cancel by 'x'
WellDone ought to default to "false" so that canceling the
form does not return a true.

However, that then means that the validating (particularly for DHCP)
needs to be handled differently.   Otherwise validation would ONLY
occur when you press OK.   (Not a terrible thing, but also not ideal.)

In any case, this is a solution I found on the internet. It seems
to work nicely. Validating still runs unless the form is closing
(via ESC, Cancel, or X), including when moving from textbox to
textbox, or tabbing to OK.

I think this also solves a lingering problem where DHCP couldn't
X out without attempting to validate.   So it feels like an all-around winner.

Step to reproduce:   Level0 ping test
1.) on net_switch0, try to ping pc0.
   -tab through and notice that pc0 resolves to 192.168.1.2 on OK button.
 2.) close with form window using X
   -notice that the ping happens anyway.   Same is true for arp and traceroute.
2019-04-29 17:15:10 -05:00
Tim Young 5d06bfd8f3 Simple typo. 192.168 instead of 102.168 2019-04-29 16:32:32 -05:00
Tim Young a0790918fb Tag PC3 on Level 6 VLAN Firewalls (Level6_VLANRouting3). It was on the default vlan instead of the student vlan. 2019-04-15 08:33:51 -05:00
Tim Young c2f41ae5b9 tracert: respond from requested IP address
If a device does a traceroute to the opposite side of a router,
the traceroute request will continue on to the next gateway
until it dies from not being able to return on the same NIC.

Instead, respond to traceroute requests from the "pinged"
ip address (so that the originator stops requesting more
tracert packets) instead of the closest address to the
originator.

Scenario: Level 3 It is dead, Jim
1.) from PC1, traceroute to the far side of router2 (192.168.3.2).
Notice that the tracert continues on two times to router0 before
dying.
2019-04-13 10:18:02 -05:00
Tim Young f5cb1875d2 Allow forwarding devices to respond to tracert_requests
Things like switches could not be tracert'd.

Scenario: Level 3 It is dead, Jim.
1.) from PC2, do a tracert to net_switch0.
Notice that there is no response.
2019-04-13 10:13:12 -05:00
Tim Young 5e39a2896d No routing/sending destination for ZeroIPString
pinging 0.0.0.0 should not go anywhere, but previously
it could be routed anywhere by default gateways etc.

Scenario: Level 3 It's dead Jim
1.) set the gateway for PC2 to router2
2.) ping net_switch1
The ping travels halfway around the network before it is dropped.

Even worse is L4 Who done it, where
originally the puzzle could be solved by
just pinging 0.0.0.0 enough times.
2019-04-13 10:08:32 -05:00
Tim Young 4a72518ccc Don't lose DHCP range when NIC address changes
When a server or firewall changes the IP address of a network
card, any DHCP ranges associated with that old number were
zeroed out.

Invalidating the range COULD be a nice feature in case the
new IP address falls within the DHCP range - thus preventing
conflicting IP addresses. So just to be nice I did allow the
range to invalidate in that situation. However, in real life
it wouldn't be so nice, and so perhaps it would actually be
better to keep the existing rules intact even if it would
cause a problem.

Scenario: Level 2 Firewall Test
-change firewall eth0 to 192.168.1.10 and eth1 to 192.168.2.20
-click OK
-edit firewall again and look at the DHCP rules
    -notice that 192.168.1 has all zeros.
    -same thing with 192.168.2
    -after the fix, the 192.168.2 rules are retained since
   2.20 doesn't conflict with the range, but 1.10 does
   conflict, so that rule was invalidated.
2019-04-13 10:05:22 -05:00
Tim Young cecd14a901 Do a better job with network interfaces when faced with vlans 2019-03-17 14:26:51 +03:00
Tim Young 073cba135e Basic renumbering working. Will blow up on a machine with multiple network interfaces. 2019-03-07 17:02:49 +03:00
Tim Young e27d960403 Add a comment about the hosts func 2019-03-06 12:38:08 +03:00
Tim Young 4014439162 Many small changes working towards renumbering a subnet. If many items are selected, we can right-click and renumber the lot of them. 2019-03-06 12:32:00 +03:00
Tim Young c0b655386e Adding a bunch of strings 2019-03-06 12:30:51 +03:00
Tim Young 199ecbcf06 Add an initial RenumberData class. Used when processing devices and figuring out which devices are part of a particular broadcast network. 2019-03-06 12:30:28 +03:00
Tim Young 966f4fe8a8 Add the ability to prompt for a network, subnet, and gateway. Used when renumbering a subnet. 2019-03-06 12:29:19 +03:00
Tim Young b1a13b95bc Add a "GetUntaggedVLAN" func to return the VLAN that is untagged on this interface. 2019-03-06 11:36:10 +03:00
Tim Young fded1f454a Add functions to find the devices connected to this device 2019-03-06 09:43:39 +03:00
Tim Young a72aec9f9a At least with this added test, the student must find and fix the hidden laptop. Not enough to solve the problem, but a step in the right direction. This test works because it requires the IP address to be unique. 2019-02-28 09:57:14 -06:00
Tim Young bed1a8a846 When the router needs to be replaced, it should not have the correct routes. You should need to add the right IP addresses and routes both. 2019-02-28 09:01:05 -06:00
Tim Young 9bf9d58c48 IPAE: DNS lookup provides subnet mask as well as IP
If the user types in a name in the IP Address Entry form,
       also replace the subnet mask.

       This is particularly useful for pinging, since ping doesn't
       allow access to the subnet mask field, and if an inappropriate
       mask is autoIP-entered, then the results might be unexpected.

       Exception for DHCP ranges: Actually, it shouldn't be necessary
       (since the IP address field is disabled for DHCP), but just
       for completeness, I ensure that the second field is not altered
       for DHCP range entries.

       Scenario: Level4, Small Subnets
       1.) fix router2, so the subnet mask is /30
       2.) from pc1, ping pc2 (which is address 192.168.1.3)
                       -lastIP sets subnet mask to 255.255.255.252
                       -that makes .3 the broadcast address
       -fix result: lastIP mask is replaced by pc2's real mask.
2019-02-27 10:16:59 -06:00
Tim Young 2a17fba36c broadcast address only applies to correct subnet
Ultimately, the problem stemmed from a ping to an address
       with the wrong subnet mask (auto-filled subnet) which turned
       the address (which should have been routed) into a local broadcast.
       Only the global broadcast, or a local broadcast should be accepted,
       not a broadcast that should be routed.

       This can be seen in Level 4, Small Subnets puzzle.
       1.) fix router2 to be /31
       2.) from pc1, ping pc2 (which turns into 192.168.1.3)
                       -autoIP filled in a subnet mask of 255.255.255.252
                       -therefore 1.3 is considered the broadcast IP.
       -result: a local broadcast on the 192.168.2 network.
       3.) from pc1, ping 192.168.1.1 or 192.168.1.4 works fine.
       4.) edit firewall1, edit route to 192.168.1.1
                       -make no changes, just hit OK
       5.) again from pc1 ping pc2
                       -now autoIP fills in subnet mask 255.255.255.0
       -result: it works
2019-02-27 08:41:58 -06:00
Tim Young 886e1d7911 allow DHCP range to cancel
The problem is easily seen most times when a DHCP range is canceled.
       The cancel completely fails to work, and refuses to cancel until
       correct values are put in start and end. (However, pressing the ESC
       key sometimes helped.)
2019-02-23 12:20:24 -06:00
Tim Young 06eb896558 cancel should also cancel auto-filled lastIP values
The problem is seen in the first puzzle if you ping
       pc0, and then edit the 0.0.0.0 gateway.   It auto-fills in
       the last-used pc0 IP address, and canceling saves that change
       instead of leaving the gateway at 0.0.0.0.

       lastIP nicely saves some typing (although it has also confused
       my student quite a bit I think), but since it updates WhatToEdit,
       that becomes the "saved" value even during a cancel.

       Instead, save the original value as a copy, and set back to
       the original value when cancellng.

       Perhaps it would be worth creating a reparse( NB_IPAddress)
       function, but this was easy to just hack together.

       Tested by pinging pc0, then editing the gateway and cancellng,
       editing the IP address and canceling.

       Next: don't add a canceled route
2019-02-23 12:16:04 -06:00
Tim Young ddebafeec9 don't add a canceled, empty route
This was especially bad when lastIP filled in default values,
       so this patch pretty much depends on the patch that cancels
       the auto-filled lastIP.

       This didn't cause a problem - it just cluttered up the routing
       table with duplicate, undeletable routes.
2019-02-23 12:08:01 -06:00
Tim Young 2ae5781bea Don't crash when adding a NIC to a PC/server (Justin) 2019-02-23 12:06:24 -06:00
23 changed files with 1066 additions and 86 deletions

View File

@ -357,7 +357,7 @@ namespace EduNetworkBuilder
tnic = ndCLonedItem.AddNic(WhatToAdd[cbQuestions.SelectedIndex]);
}
}
if(tnet != null)
if(tnet != null && tnic != null)
tnet.RegisterNICAdded(ndCLonedItem.hostname, tnic.NicName());
}
UpdateForm();

View File

@ -119,6 +119,7 @@
<DependentUpon>ListBoxWindow.cs</DependentUpon>
</Compile>
<Compile Include="NB.cs" />
<Compile Include="NBRenumberData.cs" />
<Compile Include="NBSettings.cs" />
<Compile Include="NetShape.cs" />
<Compile Include="NetTest.cs" />

View File

@ -80,6 +80,11 @@ namespace EduNetworkBuilder
}
}
public void SetIP(UInt32 newIP)
{
_ip = newIP;
}
public bool Equals(NB_IPAddress CompareWith)
{
if (_ip != CompareWith._ip) return false;
@ -241,6 +246,10 @@ namespace EduNetworkBuilder
get { return NetworkAddress + ~_mask; }
}
/// <summary>
/// Return the list of hosts in the subnet.
/// </summary>
/// <returns></returns>
public IEnumerable<UInt32> Hosts()
{
for (var host = NetworkAddress + 1; host < BroadcastAddress; host++)

View File

@ -103,6 +103,7 @@
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
this.btnCancel.CausesValidation = false;
//
// btnOK
//

View File

@ -17,10 +17,24 @@ namespace EduNetworkBuilder
{
NB_IPAddress WhatToEdit;
NB_IPAddress DHCPInterface=null;
bool WellDone = true;
bool WellDone = false;
NetworkDevice ParentDevice = null;
Point StartLocation = new Point (50,50);
NB_IPAddress SavedIPAddress = null;
ToolTip myTooltip = new ToolTip();
//variable to hold true if the for is closing
private bool isFormClosing = false;
// Contant for the close message
private const int WM_CLOSE = 16;
//override the WndProc msg to trap the WM_CLOSE message
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CLOSE)
isFormClosing = true;
base.WndProc(ref m);
}
public IPAddressEntry(NB_IPAddress toEdit, NetworkDevice ToEdit, Form ParentForm, bool JustPinging=false)
{
@ -34,6 +48,7 @@ namespace EduNetworkBuilder
ParentDevice = ToEdit;
Network myNet = NB.GetNetwork();
NB_IPAddress lastIP = myNet.RetrieveLastIP();
SavedIPAddress = new NB_IPAddress(toEdit);
WhatToEdit = toEdit;
string hostname = "";
if (ToEdit != null)
@ -148,6 +163,7 @@ namespace EduNetworkBuilder
WhatToEdit.Reparse(tbIPAddress.Text, tbNetmask.Text, tbGateway.Text);
Network myNet = NB.GetNetwork();
myNet.StoreLastIP(WhatToEdit);
WellDone = true;
Close();
}
@ -182,13 +198,16 @@ namespace EduNetworkBuilder
private void btnCancel_Click(object sender, EventArgs e)
{
if(SavedIPAddress != null)
WhatToEdit.Reparse(SavedIPAddress.GetIPString, SavedIPAddress.GetMaskString, SavedIPAddress.GetGateway.ToIpString());
UpdateFieldsFromAddress();
WellDone = false;
Close();
}
private void tbGateway_Validating(object sender, CancelEventArgs e)
{
if (isFormClosing) return;
Network mynet = NB.GetNetwork();
if (ParentDevice != null)
{
@ -216,6 +235,8 @@ namespace EduNetworkBuilder
private void tbNetmask_Validating(object sender, CancelEventArgs e)
{
if (isFormClosing) return;
UInt32 taddress = tbNetmask.Text.ParseIp();
tbNetmask.Text = taddress.ToIpString();
if (DHCPInterface != null)
@ -231,6 +252,8 @@ namespace EduNetworkBuilder
private void tbIPAddress_Validating(object sender, CancelEventArgs e)
{
if (isFormClosing) return;
UInt32 taddress;
Network mynet = NB.GetNetwork();
NB_IPAddress tIPAddress = null;
@ -238,9 +261,11 @@ namespace EduNetworkBuilder
{
tIPAddress = mynet.DNSLookup(ParentDevice, tbIPAddress.Text);
}
if(tIPAddress != null)
if (tIPAddress != null) //device name used, convert to IP address and netmask
{
taddress = tIPAddress.GetIP;
if (DHCPInterface == null)
tbNetmask.Text = tIPAddress.GetMaskString;
}
else
taddress = tbIPAddress.Text.ParseIp();
@ -258,5 +283,27 @@ namespace EduNetworkBuilder
if (tLocation.X < 0 || tLocation.Y < 0) tLocation = new Point(50, 50);
Location = tLocation;
}
public void ShowAsSubnetGateway()
{
lblIP.Text = NB.Translate("IPE_Network");
Text = NB.Translate("NB_Subnet");
myTooltip.AutoPopDelay = 5000;
myTooltip.InitialDelay = 1000;
myTooltip.ReshowDelay = 500;
// Force the ToolTip text to be displayed whether or not the form is active.
myTooltip.ShowAlways = true;
myTooltip.SetToolTip(tbIPAddress, NB.Translate("IPE_NetworkTooltip"));
myTooltip.SetToolTip(tbGateway, NB.Translate("IPE_GatewayTooltip"));
myTooltip.SetToolTip(tbNetmask, NB.Translate("IPE_NetmaskTooltip"));
myTooltip.SetToolTip(lblIP, NB.Translate("IPE_NetworkTooltip"));
myTooltip.SetToolTip(lblGateway, NB.Translate("IPE_GatewayTooltip"));
myTooltip.SetToolTip(lblNetmask, NB.Translate("IPE_NetmaskTooltip"));
ShowDialog();
}
}
}

View File

@ -755,7 +755,10 @@ namespace EduNetworkBuilder
{
NB_IPAddress newip = new NB_IPAddress(NB.ZeroIPString, NB.ZeroIPString, NB.ZeroIPString);
newip.Edit(myNetDevice, this, NB.Translate("LBW_AddRouteCreate"));
myNetDevice.AddRoute(newip);
if (!newip.Equals(new NB_IPAddress(NB.ZeroIPString, NB.ZeroIPString, NB.ZeroIPString)))
{
myNetDevice.AddRoute(newip);
}
UpdateForm();
}

View File

@ -379,6 +379,8 @@ namespace EduNetworkBuilder
public static int NormalRotation = 5;
public static int PacketDamageDistance = 25;
public static int InvalidVLAN = -999; //What we return when it is invalid
public static bool DebugActions = false;
public static bool DebugTests = false;
@ -934,6 +936,46 @@ namespace EduNetworkBuilder
return tbEvent.Text;
}
public static string ComboBoxPromptBox(string title, string prompt, List<string> Options, string value)
{
Form QuestionForm = new Form();
QuestionForm.Text = title;
Label lbPrompt = new Label();
lbPrompt.Text = prompt;
lbPrompt.Location = new Point(1, 1);
lbPrompt.Size = new Size(200, lbPrompt.Size.Height);
ComboBox Choice = new ComboBox();
List<string> tlist = new List<string>();
foreach (string tstring in Options)
{
Choice.Items.Add(tstring);
}
if (value != "" && Choice.Items.Contains(value))
{
Choice.SelectedItem = value;
}
Choice.Location = new Point(1, lbPrompt.Location.Y + lbPrompt.Height + 5);
Button Done = new Button();
Done.Click += (s, g) => { Button b = (Button)s; Form f = (Form)b.Parent; f.Close(); };
Choice.DoubleClick += (s, g) => { Button b = (Button)s; Form f = (Form)b.Parent; Choice.SelectedIndex = -1; f.Close(); }; ;
Done.Text = NB.Translate("_Done");
Done.Location = new Point(1, Choice.Location.Y + Choice.Height + 5);
QuestionForm.Controls.Clear();
QuestionForm.Controls.Add(Choice);
QuestionForm.Controls.Add(Done);
QuestionForm.Controls.Add(lbPrompt);
QuestionForm.AcceptButton = Done;
QuestionForm.FormBorderStyle = FormBorderStyle.FixedDialog;
QuestionForm.AutoSize = true;
QuestionForm.Height = Done.Location.Y + Done.Height + 5; //This is too small for the form, it autosizes to "big enough"
QuestionForm.Width = Choice.Location.X + Choice.Width + 5;
QuestionForm.ShowDialog();
if (Choice.SelectedIndex >= 0) return Choice.SelectedItem.ToString();
return "";
}
public static Dictionary<string, bool> CheckPromptBox(Dictionary<string, bool> Checks)
{

View File

@ -0,0 +1,293 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EduNetworkBuilder
{
public class NBRenumberer
{
private bool renumbered = false;
public List<NBRenumberData> ListOfItems = new List<NBRenumberData>();
public void Count(string what)
{
NBRenumberData entry = DataFromName(what);
if(entry != null)
{
entry.ActiveCount++;
return;
}
//If we get here, we have not found it yet.
NBRenumberData One = new NBRenumberData(what, ListOfItems.Count);
One.ActiveCount++;
ListOfItems.Add(One);
}
public void SetAsGateway(string what)
{
NBRenumberData GW = DataFromName(what);
if (GW == null) {
GW = new NBRenumberData(what, ListOfItems.Count);
ListOfItems.Add(GW);
}
GW.isTheGateway = true;
GW.UpdateSortOrder();
//We can only have one gateway. Make sure all the rest are set not to be the GW
foreach(NBRenumberData one in ListOfItems)
{
if (one != GW) {
one.isTheGateway = false;
one.UpdateSortOrder();
}
}
}
public NBRenumberData DataFromName(string hostname)
{
foreach (NBRenumberData NBRD in ListOfItems)
{
if (NBRD.Hostname == hostname)
{
return NBRD;
}
}
return null;
}
public bool TryRenumbering(NB_IPAddress Network, NB_IPAddress Gateway)
{
renumbered = true;
//Separate out the devices by type
// Find the gateway too
int biggestcount = 0;
int spacing = 10;
bool HasGateway = false;
foreach (NBRenumberData NBRD in ListOfItems)
{
if (NBRD.ActiveCount > biggestcount) biggestcount = NBRD.ActiveCount;
}
//now, we can prune off everything that is not part of biggestcount.
for(int i=ListOfItems.Count-1; i>=0; i--)
{
if (ListOfItems[i].ActiveCount != biggestcount)
ListOfItems.RemoveAt(i);
else
{
if (ListOfItems[i].isTheGateway) HasGateway = true;
ListOfItems[i].SuggestedIP = "";
}
}
if (!HasGateway)
for (int i = ListOfItems.Count - 1; i >= 0; i--)
{
if (ListOfItems[i].Device.HasIPAddress(Gateway))
SetAsGateway(ListOfItems[i].Hostname);
}
int switches = 0;
int servers = 0;
int printers = 0;
int wireless = 0;
int clients = 0;
foreach(NBRenumberData NBRD in ListOfItems)
{
switch(NBRD.TypeString())
{
case "client":
clients++;
break;
case "printer":
printers++;
break;
case "switch":
switches++;
break;
case "server":
servers++;
break;
case "wireless":
wireless++;
break;
}
}
//Decide on which way we want to do this.
biggestcount = 0;
if (servers > biggestcount) biggestcount = servers;
if (switches > biggestcount) biggestcount = switches;
if (printers > biggestcount) biggestcount = printers;
if (wireless > biggestcount) biggestcount = wireless;
if (clients > biggestcount) biggestcount = clients;
ListOfItems.Sort((p, q) => p.sortorder.CompareTo(q.sortorder));
//If it works to do 10 for each bunch, do that. Otherwise, see what the smallest bunch that works is.
if (biggestcount < 10)
{
spacing = 10;
}
if (biggestcount > 10)
spacing = 99; //Don't bother with anything fancy. Punt if it does not fit the first time
//Fallback is to simply count up from the gateway.
if (Network.NumberOfHosts < ListOfItems.Count)
return false;
if(spacing * 5 > Network.NumberOfHosts)
{
renumberlist(Network, 1, "");
}
else
{
//We can do this in parts
renumberlist(Network, 1, "Gateway");
renumberlist(Network, 2, "server");
renumberlist(Network, spacing * 1, "switch");
renumberlist(Network, spacing * 2, "wireless");
renumberlist(Network, spacing * 3, "printer");
renumberlist(Network, spacing * 4, "client");
}
return true;
}
private void renumberlist(NB_IPAddress Network, int Base, string filter)
{
int count = Base;
for (int i = 0; i < ListOfItems.Count; i++)
{
if (ListOfItems[i].SuggestedIP != "") continue;
if (filter == "" || ListOfItems[i].TypeString() == filter || filter == "Gateway" && ListOfItems[i].isTheGateway)
{
NB_IPAddress next = new NB_IPAddress(Network);
next._ip += (UInt32)count;
ListOfItems[i].SuggestedIP = next.GetIPString;
count++;
}
}
}
public void DoRenumbering(NB_IPAddress Network, NB_IPAddress Gateway, int vlanID)
{
if (!renumbered) TryRenumbering(Network, Gateway);
//loop through and set all the IPs and the gateway IP if not DHCPS
for(int i = 0; i < ListOfItems.Count; i++)
{
ListOfItems[i].Device.RenumberIP(ListOfItems[i].SuggestedIP, Gateway, vlanID);
}
}
}
public class NBRenumberData
{
public string Hostname = "";
public NetworkDevice Device {
get {
Network myNet = NB.GetNetwork();
if (myNet == null) return null;
return myNet.DeviceFromName(Hostname);
}
}
public int ActiveCount=0;
public string nicname;
public string SuggestedIP;
public int sortorder = 0;
private int _index = 0;
public NetworkComponentType mytype = NetworkComponentType.none;
public bool isTheGateway = false;
private bool _isRouter = false;
/// <summary>
/// Return true if the Device specified by hostname does routing.
/// </summary>
public bool IsRouter {
get {
if (_isRouter) return true;
NetworkDevice ND = Device;
if(ND.RoutesPackets())
{
_isRouter = true;
return true;
}
return false;
}
}
public NBRenumberData(string hostname, int index)
{
Hostname = hostname;
NetworkDevice nd = Device;
mytype = nd.myType;
_index = index;
UpdateSortOrder();
}
public void UpdateSortOrder()
{
switch (TypeString())
{
case "client":
sortorder=5000;
break;
case "printer":
sortorder = 4000;
break;
case "switch":
sortorder=2000;
break;
case "server":
sortorder=1000;
break;
case "wireless":
sortorder=3000;
break;
}
sortorder = sortorder + _index;
if (isTheGateway) sortorder = 0;
}
public string TypeString()
{
string what = "";
switch (mytype)
{
case NetworkComponentType.cellphone:
case NetworkComponentType.ip_phone:
case NetworkComponentType.laptop:
case NetworkComponentType.pc:
case NetworkComponentType.tablet:
what = "client";
break;
case NetworkComponentType.printer:
case NetworkComponentType.copier:
what = "printer";
break;
case NetworkComponentType.net_hub:
case NetworkComponentType.net_switch:
what = "switch";
break;
case NetworkComponentType.firewall:
case NetworkComponentType.router:
case NetworkComponentType.server:
what = "server";
break;
case NetworkComponentType.wap:
case NetworkComponentType.wbridge:
case NetworkComponentType.wrepeater:
case NetworkComponentType.wrouter:
what = "wireless";
break;
}
return what;
}
}
}

View File

@ -919,6 +919,12 @@ namespace EduNetworkBuilder
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("_Delete"));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_Delete_Click;
if(!myNetwork.LoadedFromResource)
{
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("NB_Renumber"));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkRenumber;
}
//We can color-code multiple items
if (myNetwork.VLANsEnabled)
{
@ -1129,6 +1135,150 @@ namespace EduNetworkBuilder
}
/// <summary>
/// Try to renumber a chunk of a network
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbNetworkRenumber(object sender, EventArgs e)
{
//come up with a plan
// sort items by type
// loop through the items
// come up with the numbers we want to use
// Decide which nics to change
// On a router, find the nic that is connected to other items in the list
// On other devices, find first nic that is connected that is not DHCP
// track hostname, nicname, ip_address
//print out a list of what we are going to do
//Ask if we want to do it. Yes/No
//do it
if (ItemsSelected.Count > 0)
{
//This next entry should never happen.
if (ItemsSelected.Count < 2)
{
MessageBox.Show("You need to have more items selected");
return;
}
int ChosenVlanID = 1;
if(myNetwork != null && myNetwork.VLANsEnabled)
{
List<string> vnames = new List<string>();
foreach(VLANName vn in myNetwork.VlanNames)
{
vnames.Add(vn.Name);
}
string ChosenVlanName = "";
if (vnames.Count > 0) ChosenVlanName = vnames[0]; //Usually "Default"
if (vnames.Count > 1)
{
//we need to prompt
ChosenVlanName = NB.ComboBoxPromptBox(NB.Translate("NB_ChooseVLANRenumberTitle"), NB.Translate("NB_ChooseVLANRenumber"), vnames, vnames[0]);
}
ChosenVlanID = myNetwork.VLANIDFromName(ChosenVlanName);
}
NB_IPAddress prompted = new NB_IPAddress("192.168.1.0","255.255.255.0","192.168.1.1");
IPAddressEntry IPE = new IPAddressEntry(prompted, null, this, false);
//Read in the settings we will use
IPE.ShowAsSubnetGateway();
//pull out the gateway address
NB_IPAddress gw = new NB_IPAddress(prompted.GetGateway.ToIpString(), prompted._mask.ToIpString(),IPAddressType.gw);
//pull out the network address
NB_IPAddress network = new NB_IPAddress(prompted.NetworkAddress.ToIpString(), prompted._mask.ToIpString(), IPAddressType.gw);
//We need to find the gateway device. If no such device exists, find the most likely candidate
string gateway_name = myNetwork.ReverseDNSLookup(ItemsSelected[0],gw);
NetworkDevice gwDevice = myNetwork.DeviceFromName(gateway_name);
if(gwDevice == null)
{
//Make a list of possibilities
//Prompt user to select one of them
List<NetworkDevice> gwdevices = new List<NetworkDevice>();
for (int i = ItemsSelected.Count - 1; i >= 0; i--)
{
if (ItemsSelected[i].RoutesPackets()) gwdevices.Add(ItemsSelected[i]);
}
if (gwdevices.Count == 1) gwDevice = gwdevices[0];
else
{
//We need to prompt which device
List<string> names = new List<string>();
foreach(NetworkDevice one in gwdevices)
{
names.Add(one.hostname);
}
names.Sort();
gateway_name = NB.ComboBoxPromptBox(NB.Translate("_Gateway"), NB.Translate("NB_ChooseGateway"), names, names[0]);
gwDevice = myNetwork.DeviceFromName(gateway_name);
}
}
if (gwDevice == null) return; //No gateway device selected
NBRenumberer Renumberer = new NBRenumberer();
//If we get here, we have a gateway and a list of items to renumber.
//Loop through all the items
//Find find all connected items
//loop through all connected items & count them (excluding them if they are not selected)
//set the gateway.
//count them and exclude items that are not within the threshhold.
foreach(NetworkDevice one in ItemsSelected)
{
List<NetworkDevice> alreadydone = new List<NetworkDevice>();
List<NetworkDevice> connections = one.ConnectedTo();
for(int i=0; i< connections.Count; i++)
{
NetworkDevice connection = connections[i];
//If we have not done it yet
if (!ItemsSelected.Contains(connection))
continue;
if (myNetwork.VLANsEnabled && (ChosenVlanID != connection.PrimaryVLAN() && connection.myType != NetworkComponentType.net_switch))
continue; //Skip the device if it is not on the primary vlan, and is not a switch (asuming switches are taggexd)
if (!alreadydone.Contains(connection))
{
alreadydone.Add(connection);
if(!connection.RoutesPackets() || connection.myType == NetworkComponentType.wrouter)
connections.AddRange(connection.ConnectedTo(true));
Renumberer.Count(connection.hostname);
}
}
}
Renumberer.SetAsGateway(gwDevice.hostname);
Renumberer.TryRenumbering(network, gw);
if (Renumberer.ListOfItems.Count > network.NumberOfHosts)
{
//Not enough room in the subnet for the various items.
MessageBox.Show("There are not enough IP addresses in the subnet you specified for the number of items we need to renumber.");
return;
}
//We should print off the things we are hoping to do.
string message = "What we are trying to do:\n";
foreach(NBRenumberData NBRD in Renumberer.ListOfItems)
{
message += NBRD.Hostname + " " + NBRD.TypeString() + " -> " + NBRD.SuggestedIP + "\n";
}
DialogResult answer = MessageBox.Show(message,"Renumber?",MessageBoxButtons.OKCancel);
if (answer == DialogResult.OK)
Renumberer.DoRenumbering(network, gw, ChosenVlanID);
}
}
private void pbNetworkView_Hide_Click(object sender, EventArgs e)
{
if (ItemClickedOn != null)

View File

@ -35,7 +35,7 @@ namespace EduNetworkBuilder
public bool IsBurned = false;
public Color BackgroundColor = Color.Empty;
protected Color MorphColor = Color.Empty;
public List<FirewallRule> FirewallRules = new List<FirewallRule>();
public List<FirewallRule> FirewallRules = new List<FirewallRule>();
public bool PowerOff = false;
private List<string> tracertmessages = new List<string>();
public int BadSprayCount = 0;
@ -49,7 +49,7 @@ namespace EduNetworkBuilder
myType = what;
SetImageFromType(what);
NetworkCard tnic = new NetworkCard(0,GetUniqueIdentifier,hostname,NicType.lo);
NetworkCard tnic = new NetworkCard(0, GetUniqueIdentifier, hostname, NicType.lo);
NICs.Add(tnic);
if (what == NetworkComponentType.net_switch || what == NetworkComponentType.net_hub)
{
@ -58,7 +58,7 @@ namespace EduNetworkBuilder
tnic = new NetworkCard(0, GetUniqueIdentifier, hostname, NicType.management_interface);
NICs.Add(tnic);
}
for(int looper=1; looper < 8; looper++)
for (int looper = 1; looper < 8; looper++)
{
tnic = new NetworkCard(looper, GetUniqueIdentifier, hostname, NicType.port);
NICs.Add(tnic);
@ -71,16 +71,16 @@ namespace EduNetworkBuilder
tnic = new NetworkCard(0, GetUniqueIdentifier, hostname);
NICs.Add(tnic);
}
if(what == NetworkComponentType.router)
if (what == NetworkComponentType.router)
{
tnic = new NetworkCard(1, GetUniqueIdentifier, hostname);
NICs.Add(tnic);
}
//**********Wireless***********
//Add a wireless network card to laptops, wireless bridge and wireless repeater
if (what == NetworkComponentType.laptop )
if (what == NetworkComponentType.laptop)
{
tnic = new NetworkCard(NICs.Count(), GetUniqueIdentifier, hostname,NicType.wlan); //Add a wireless nic
tnic = new NetworkCard(NICs.Count(), GetUniqueIdentifier, hostname, NicType.wlan); //Add a wireless nic
tnic.UsesDHCP = true;
NICs.Add(tnic);
}
@ -161,8 +161,8 @@ namespace EduNetworkBuilder
NICs.Add(tnic);
//Add one wan port
tnic = new NetworkCard(0, GetUniqueIdentifier, hostname, NicType.wan);
NICs.Insert(1,tnic); //Make this first in the list
}
NICs.Insert(1, tnic); //Make this first in the list
}
if (what == NetworkComponentType.cellphone || what == NetworkComponentType.tablet)
{
NICs.Clear();
@ -179,9 +179,9 @@ namespace EduNetworkBuilder
public int CountNics(NicType TheType)
{
int count = 0;
foreach(NetworkCard nic in NICs)
foreach (NetworkCard nic in NICs)
{
if(nic.GetNicType == TheType)
if (nic.GetNicType == TheType)
{
count++;
}
@ -197,7 +197,7 @@ namespace EduNetworkBuilder
string tname = TheType.ToString() + count.ToString();
foreach (NetworkCard nic in NICs)
{
if(nic.NicName() == tname)
if (nic.NicName() == tname)
{
found = true;
break;
@ -236,7 +236,7 @@ namespace EduNetworkBuilder
CanAddNics = true;
setNicsCanUseDHCP(false);
}
if (myType == NetworkComponentType.pc || myType == NetworkComponentType.laptop ||
if (myType == NetworkComponentType.pc || myType == NetworkComponentType.laptop ||
myType == NetworkComponentType.copier || myType == NetworkComponentType.printer ||
myType == NetworkComponentType.tablet || myType == NetworkComponentType.cellphone)
{
@ -276,7 +276,7 @@ namespace EduNetworkBuilder
private void setNicsCanUseDHCP(bool CanUse)
{
foreach(NetworkCard nic in NICs)
foreach (NetworkCard nic in NICs)
{
//if the device must use DHCP. we set it here.
if (MustUseDHCP && nic.CanUseDHCP)
@ -355,37 +355,37 @@ namespace EduNetworkBuilder
NetworkLink nl;
if (myNet != null)
{
foreach(NetworkCard nic in NICs)
{
if(nic.ConnectedLink != -1)
{
foreach (NetworkCard nic in NICs)
{
if (nic.ConnectedLink != -1)
{
nl = myNet.GetLinkFromID(nic.ConnectedLink);
if(nl != null)
if (nl != null)
{
myNet.RemoveComponent(nl);
nl.Destroy();
}
nic.ConnectedLink = -1;
}
}
}
}
}
}
public void EditGateway(Form ParentForm)
{
DefaultGW.Edit(this,ParentForm,NB.Translate("ND_EdtGteway"));
DefaultGW.Edit(this, ParentForm, NB.Translate("ND_EdtGteway"));
}
public NB_IPAddress GetGateway()
{
if(!HasNonDHCPConnected() && CanUseDHCP)
{
foreach(NetworkCard nic in NICs)
if (!HasNonDHCPConnected() && CanUseDHCP)
{
foreach (NetworkCard nic in NICs)
{
if(nic.UsesDHCP)
if (nic.UsesDHCP)
{
List<NB_IPAddress> tlist = nic.IPAddressList();
if(tlist.Count > 0)
if (tlist.Count > 0)
{
NB_IPAddress newIP = new NB_IPAddress(tlist[0].GetGateway.ToIpString());
return newIP;
@ -422,7 +422,7 @@ namespace EduNetworkBuilder
XmlNodeType myNodetype = Individual.NodeType;
if (myNodetype == XmlNodeType.Element)
{
switch(Individual.Name.ToLower())
switch (Individual.Name.ToLower())
{
case "location":
string[] pointstr = Individual.InnerText.Split(',');
@ -450,13 +450,13 @@ namespace EduNetworkBuilder
newNic = new NetworkCard(Individual);
//if (myType == NetworkComponentType.wap && newNic.GetNicType == NicType.eth)
//{
// //This happened once upon a time. Waps did not have management interfaces.
// //Make a management interface for the wap and move the IP from the eth to that.
// //Then, change the nic to a port instead of an eth.
// NetworkCard tNic = new NetworkCard(newNic);
// tNic.ChangeType(NicType.management_interface);
// NICs.Add(tNic);
// newNic.ChangeType(NicType.port);
// //This happened once upon a time. Waps did not have management interfaces.
// //Make a management interface for the wap and move the IP from the eth to that.
// //Then, change the nic to a port instead of an eth.
// NetworkCard tNic = new NetworkCard(newNic);
// tNic.ChangeType(NicType.management_interface);
// NICs.Add(tNic);
// newNic.ChangeType(NicType.port);
//}
NICs.Add(newNic);
break;
@ -474,7 +474,7 @@ namespace EduNetworkBuilder
bool.TryParse(Individual.InnerText, out isDHCPServer);
break;
case "dhcprange":
NB_IPAddress dhcpip = new NB_IPAddress(Individual);
NB_IPAddress dhcpip = new NB_IPAddress(Individual);
DHCPRanges.Add(dhcpip);
break;
case "hasadvfirewall":
@ -510,13 +510,13 @@ namespace EduNetworkBuilder
writer.WriteElementString("mytype", myType.ToString());
writer.WriteElementString("isdns", isDNSServer.ToString());
writer.WriteElementString("isdhcp", isDHCPServer.ToString());
if(IsBurned)
if (IsBurned)
writer.WriteElementString("isburned", IsBurned.ToString());
if (HasAdvFirewall)
writer.WriteElementString("hasadvfirewall", HasAdvFirewall.ToString());
if (MorphColor != Color.Empty)
if (MorphColor != Color.Empty)
writer.WriteElementString("morphcolor", MorphColor.Name);
if(PowerOff == true)
if (PowerOff == true)
writer.WriteElementString("poweroff", PowerOff.ToString());
if (isInvisible == true)
writer.WriteElementString("isinvisible", isInvisible.ToString());
@ -584,21 +584,21 @@ namespace EduNetworkBuilder
return NB.Translate("ND_MicrowaveTooltip");
foreach (NetworkCard nic in NICs)
{
if (nic.GetNicType == NicType.wport || nic.GetNicType == NicType.port)
if (nic.GetNicType == NicType.wport || nic.GetNicType == NicType.port)
continue;
foreach(string addr in nic.IPAddresses())
foreach (string addr in nic.IPAddresses())
{
answer += System.Environment.NewLine + addr;
answer += System.Environment.NewLine + addr;
}
}
if(BackgroundColor != Color.Empty)
if (BackgroundColor != Color.Empty)
{
//There is something wrong with it?
Network myNet = NB.GetNetwork();
List<string> DeviceMessages = myNet.GetTestMessages(hostname);
foreach (string tString in DeviceMessages)
{
answer += System.Environment.NewLine + tString;
answer += System.Environment.NewLine + tString;
}
}
return answer;
@ -607,18 +607,18 @@ namespace EduNetworkBuilder
public List<string> ListOfConnectedHosts()
{
List<string> thelist = new List<string>();
foreach(NetworkCard nic in NICs)
foreach (NetworkCard nic in NICs)
{
if(nic.ConnectedLink != -1)
if (nic.ConnectedLink != -1)
{
Network myNet = NB.GetNetwork();
NetworkLink Link = myNet.GetLinkFromID(nic.ConnectedLink);
if(Link != null)
if (Link != null)
{
NetworkDevice tmp = myNet.GetDeviceFromID(Link.Src);
if (tmp == null) continue;
if (tmp.hostname != hostname) thelist.Add(tmp.hostname);
tmp = myNet.GetDeviceFromID(Link.Dst);
tmp = myNet.GetDeviceFromID(Link.Dst);
if (tmp.hostname != hostname) thelist.Add(tmp.hostname);
}
}
@ -655,6 +655,196 @@ namespace EduNetworkBuilder
}
}
/// <summary>
/// Return the list of devices connected to this device
/// </summary>
/// <param name="skipwan">For routers, do not show things connected on the WAN</param>
/// <returns>A list of devices</returns>
public List<NetworkDevice> ConnectedTo(bool skipwan= false)
{
List<NetworkDevice> connected = new List<NetworkDevice>();
foreach (NetworkCard nic in NICs)
{
//We want to skip connections through the wan when searching a broadcast network
if (!(myType == NetworkComponentType.wrouter && skipwan && nic.GetNicType == NicType.wan))
{
NetworkDevice nd = ConnectedTo(nic);
if (nd != null) connected.Add(nd);
}
}
return connected;
}
/// <summary>
/// return the device this nic is attached to
/// </summary>
/// <param name="NIC"></param>
/// <returns></returns>
public NetworkDevice ConnectedTo(NetworkCard NIC)
{
return NIC.ConnectedTo();
}
/// <summary>
/// return the device this nic is attached to
/// </summary>
/// <param name="NIC">the network card ID</param>
/// <returns></returns>
public NetworkDevice ConnectedTo(HostNicID NIC)
{
NetworkCard nic = NicFromID(NIC);
if (nic == null) return null;
return nic.ConnectedTo();
}
/// <summary>
/// return the device this nic is attached to
/// </summary>
/// <param name="nicname">The network card name</param>
/// <returns></returns>
public NetworkDevice ConnectedTo(string nicname)
{
NetworkCard nic = NicFromName(nicname);
if (nic == null) return null;
return nic.ConnectedTo();
}
public int VLANFromNIF(NetworkInterface nif, int level = 0)
{
level++;
if (DoesVLANs())
{
//This device itself does vlans
int vlan = nif.GetUntaggedVLAN();
if (vlan != NB.InvalidVLAN)
{
return vlan;
}
}
if (nif == null) return NB.InvalidVLAN;
NetworkCard nic = NicFromID(nif.AttachedToHostNic);
if (nic == null) return NB.InvalidVLAN; //Nothing
if (level > 5) return NB.InvalidVLAN;
return VLANFromNIC(nic, level);
}
public int VLANFromNIC(NetworkCard nic, int level=0)
{
level++;
int vlan = NB.InvalidVLAN;
if (DoesVLANs())
{
foreach (NetworkInterface nif in nic.interfaces)
{
int tvlan = NB.InvalidVLAN;
if(DoesVLANs())
tvlan = VLANFromNIF(nif, level);
if (tvlan != NB.InvalidVLAN)
{
if (vlan != NB.InvalidVLAN && vlan != tvlan)
return NB.InvalidVLAN; //We have multiple VLANs defined on this nic. Cannot determine it from the nic. Need to look using nif
vlan = tvlan;
}
}
return vlan;
}
//If the device does not do vlans, we need to trace the wire to the device.
NetworkDevice FarEnd = ConnectedTo(nic);
if (FarEnd == null) return NB.InvalidVLAN; //Nothing connected to this link
//if it is a switch or wrouter(does vlans), return vlan for the device
if (FarEnd.myType == NetworkComponentType.net_switch || FarEnd.myType == NetworkComponentType.wrouter)
return FarEnd.VLANFromSwitchPort(hostname);
//if it is a hub, return invalid
if (FarEnd.myType == NetworkComponentType.net_hub)
return NB.InvalidVLAN;
//if it is a wireless device, find the vlan the device is attached to.
if (FarEnd.IsWirelessForwarder())
{
return FarEnd.PrimaryVLAN();
}
return NB.InvalidVLAN;
}
/// <summary>
/// Used by PrimaryVLAN
/// </summary>
/// <param name="tList"></param>
/// <returns></returns>
private int ProcessVLANlist(List<NetworkCard> tList)
{
int VLAN = NB.InvalidVLAN;
int tvlan = NB.InvalidVLAN;
foreach(NetworkCard nic in tList)
{
tvlan = VLANFromNIC(nic);
if(VLAN != NB.InvalidVLAN && tvlan != VLAN)
{
//We have multiple VLANs defined on these nics. We do not know what is primary
return NB.InvalidVLAN;
}
VLAN = tvlan;
}
return VLAN;
}
/// <summary>
/// Return the primary vlan of the device.
/// </summary>
/// <returns></returns>
public int PrimaryVLAN()
{
int tVLAN;
List<NetworkCard> Connections;
Connections = NICsFromTypeNic(NicType.management_interface);
tVLAN = ProcessVLANlist(Connections);
if (tVLAN != NB.InvalidVLAN) return tVLAN;
//Connections = NICsFromTypeNic(NicType.wan); //If the device has a wan vlan defined
//tVLAN = ProcessVLANlist(Connections);
//if (tVLAN != NB.InvalidVLAN) return tVLAN;
Connections = NICsFromTypeNic(NicType.eth);
tVLAN = ProcessVLANlist(Connections);
if (tVLAN != NB.InvalidVLAN) return tVLAN;
Connections = NICsFromTypeNic(NicType.wlan);
tVLAN = ProcessVLANlist(Connections);
if (tVLAN != NB.InvalidVLAN) return tVLAN;
return NB.InvalidVLAN;
}
/// <summary>
/// On a switch, return the vlan that hostname is attached to. Returns invalid if not found on this switch
/// </summary>
/// <param name="hostname">the hostname of the device</param>
/// <returns>nb.invalid if it is not attached to this switch, or if this is not a switch</returns>
public int VLANFromSwitchPort(string hostname)
{
if (myType == NetworkComponentType.net_hub) return NB.InvalidVLAN; //Hubs do not know what vlan they are on
if(myType == NetworkComponentType.net_switch || myType == NetworkComponentType.wrouter)
{
//We want to find the port the hostname is on.
foreach(NetworkCard nic in NICs)
{
NetworkDevice FarEnd = ConnectedTo(nic); //Get the device at the far end
if (FarEnd == null) continue;
if(FarEnd.hostname == hostname)
{
//This is the port the host is on
return VLANFromNIC(nic);
}
}
}
return NB.InvalidVLAN;
}
public int VLANFromIP(string ip)
{
NetworkInterface nif = InterfaceFromIP(ip);
if (nif == null) return NB.InvalidVLAN; //Nothing
return VLANFromNIF(nif);
}
/// <summary>
/// Check to see if the device has a link to the specified host
/// </summary>
@ -1164,6 +1354,73 @@ namespace EduNetworkBuilder
}
return null;
}
public NetworkInterface InterfaceFromIP(string IP)
{
foreach (NetworkCard nic in NICs)
{
foreach (NetworkInterface nif in nic.interfaces)
{
if (nif.myIP.GetIPString == IP)
return nif;
}
}
return null;
}
public bool RenumberIP(string newip, NB_IPAddress gateway, int vlanID)
{
DefaultGW = new NB_IPAddress(gateway);
//figure out which interface to change.
if (!RenumberIP(newip, gateway, NicType.management_interface, vlanID))
if (!RenumberIP(newip, gateway, NicType.eth, vlanID))
return RenumberIP(newip, gateway, NicType.wlan, vlanID);
return true;
}
private bool RenumberIP(string newip, NB_IPAddress gateway, NicType what, int vlan)
{
List<NetworkCard> smalllist = NICsFromTypeNic(what);
smalllist.Sort((p, q) => p._nic_name.CompareTo(q._nic_name));
foreach (NetworkCard nic in smalllist)
{
//see if we can renumber this one
//It cannot be dhcp, and must be connected.
if((!nic.UsesDHCP && nic.isConnected(false)) || nic.GetNicType == NicType.management_interface)
{
//If we are doing vlans, the vlan should match the interface if eth
//If we are doing vlans, the vlan should match if we are doing management interface
//
//right now, just do it.
NetworkInterface nif = nic.PrimaryInterface();
if(nif == null)
{ //There are multiple interfaces, or there are no interfaces.
//If multiple interfaces, try one with the specified vlan.
nif = nic.InterfaceFromVlanTag(vlan);
}
if (nif != null)
{
nif.myIP = new NB_IPAddress(newip, gateway._mask.ToIpString(), IPAddressType.ip);
return true;
}
}
}
return false;
}
public NetworkCard NicFromIP(string IP)
{
foreach (NetworkCard nic in NICs)
{
foreach(NetworkInterface nif in nic.interfaces)
{
if (nif.myIP.GetIPString == IP)
return nic;
}
}
return null;
}
public NetworkCard NicFromID(HostNicID ID)
{
return NicFromID(ID.NicID);
@ -1431,7 +1688,12 @@ namespace EduNetworkBuilder
public bool HasBroadcastAddress(NB_IPAddress dest)
{
if (dest.BroadcastAddress == dest.GetIP) return true;
foreach(NetworkCard nic in NICs)
//This "fixes" a strange fringe case of when we configure a subnet such that
//a packet that is traversing the network suddenly is a broadcast packet on the
//target network. Gotta have odd subnetting for this to happen
if (NB.BroadcastIPString == dest.GetIPString) return true;
foreach (NetworkCard nic in NICs)
{
if (nic.HasBroadcastAddresses(dest))
return true;
@ -1544,6 +1806,24 @@ namespace EduNetworkBuilder
RouteTable.AddRange(ndCopyFrom.RouteTable);
DHCPRanges.Clear();
DHCPRanges.AddRange(ndCopyFrom.DHCPRanges);
//if the IP address has changed, also update the corresponding address in DHCP rules
foreach (NB_IPAddress dhcpIP in DHCPRanges)
{
foreach (NetworkCard nic in NICs)
{
NetworkInterface matchingIF = nic.LocalInterface(dhcpIP, null);
if (matchingIF != null && !matchingIF.myIP.Equals(dhcpIP.GetIP) && !matchingIF.myIP.Equals(0))
{
//only validate the entry if the new address doesn't conflict with the DHCP range.
UInt32 nStartingDHCP = dhcpIP.GetMask;
UInt32 nEndingDHCP = dhcpIP.GetGateway;
if (matchingIF.myIP.GetIP < nStartingDHCP || matchingIF.myIP.GetIP > nEndingDHCP)
{
dhcpIP.SetIP(matchingIF.myIP.GetIP);
}
}
}
}
DHCPLeases.Clear();
DHCPLeases.AddRange(ndCopyFrom.DHCPLeases);
@ -1823,7 +2103,7 @@ namespace EduNetworkBuilder
//Change this. Need a new ProcessArrival
if (tPacket.MyType != PacketType.dhcp_answer) //If it is a match, it should be handled elsewhere
ProcessArrival(tPacket);
if (ExactMatch && tPacket.isFinshed())
if (ExactMatch && tPacket.isFinished())
return;
}
@ -1870,7 +2150,7 @@ namespace EduNetworkBuilder
}
if (tPacket.isFinshed() && !BroadcastMatch) return;
if (tPacket.isFinished() && !BroadcastMatch) return;
NetworkCard dNic = null;
NetworkCard sNic = null;
@ -2552,7 +2832,12 @@ namespace EduNetworkBuilder
NetworkCard tCard = null;
NB_IPAddress DestAddr;
string DHCPGW = "";
foreach( NB_IPAddress ip in RouteTable)
//Do not ping the zero string. Should not go anywhere
if (dest != null && dest.GetIPString == NB.ZeroIPString)
return new NB_IPAddress(NB.ZeroIPString);
foreach ( NB_IPAddress ip in RouteTable)
{
if (ip.IsLocal(dest))
return new NB_IPAddress(ip.GetGateway.ToIpString());//We return the gateway
@ -2785,6 +3070,19 @@ namespace EduNetworkBuilder
return null;
}
private List<NetworkCard> NICsFromTypeNic(NicType What)
{
List<NetworkCard> tList = new List<NetworkCard>();
foreach (NetworkCard nic in NB.Randomize(NICs).ToList())
{
if (nic.GetNicType == What)
{
tList.Add(nic);
}
}
return tList;
}
public NB_IPAddress BestIPForThis(NetworkDevice Source=null)
{
NB_IPAddress answer=null;
@ -2912,14 +3210,16 @@ namespace EduNetworkBuilder
}
}
if (!ForwardsPackets())
if (!ForwardsPackets() || HasIPAddress(tPacket.destIP))
{
//Traceroute bounce-back
if(tPacket.MyType == PacketType.tracert_request)
if (tPacket.MyType == PacketType.tracert_request)
{
if (ProcessTracertPacket(tPacket)) return; //the packet stops if it gets bounced.
}
}
if (!ForwardsPackets())
{
if (tPacket.MyType == PacketType.dhcp_request && !isDHCPServer)
{
tPacket.AddMessage(DebugLevel.debug, NB.LeftPad(hostname) + " " +string.Format(NB.Translate("ND_DoInFromLnkDeaf")));
@ -2990,7 +3290,12 @@ namespace EduNetworkBuilder
//Console.WriteLine(" Tracert bounce: " + tPacket.OrigTTL + " " + hostname + " " + tPacket.payloadData);
//Finish setting up the new packet - sending it back
nPacket.sourceIP = new NB_IPAddress(NB.ZeroIPString);
// respond from requested address, not outgoing address: important for routers.
if (HasIPAddress(tPacket.destIP))
nPacket.sourceIP = tPacket.destIP;
else
nPacket.sourceIP = new NB_IPAddress(NB.ZeroIPString);
nPacket.TsourceIP = new NB_IPAddress(NB.ZeroIPString);
myNet.addPacket(nPacket);
//Console.WriteLine(" Tracert bounce pkt:" + nPacket.OrigTTL + nPacket.payloadData);

View File

@ -123,6 +123,16 @@ namespace EduNetworkBuilder
return VLANTagType.Forbidden; //if not defined, it is forbidden
}
public int GetUntaggedVLAN()
{
foreach (VLANInfo vin in VLANs)
{
if (vin.Tag == VLANTagType.Untagged)
return vin.ID;
}
return NB.InvalidVLAN;
}
public int GetNonForbiddenVLANID()
{
foreach(VLANInfo vin in VLANs)
@ -130,7 +140,7 @@ namespace EduNetworkBuilder
if (vin.Tag != VLANTagType.Forbidden)
return vin.ID;
}
return -999;
return NB.InvalidVLAN;
}
public void SetVLANTag(int id, VLANTagType Tag)

View File

@ -489,7 +489,7 @@ namespace EduNetworkBuilder
return false;
}
public bool isFinshed()
public bool isFinished()
{
if (_MyStatus == PacketStatus.finished_ok) return true;
if (_MyStatus == PacketStatus.finished_failed) return true;

View File

@ -70,7 +70,7 @@
<interface>
<nicname>management_interface0</nicname>
<myip>
<ip>102.168.1.4</ip>
<ip>192.168.1.4</ip>
<mask>255.255.255.0</mask>
<gateway>0.0.0.0</gateway>
<type>ip</type>

View File

@ -2,8 +2,8 @@
<EduNetworkBuilder>
<!--This is a network file for EduNetworkBuilder.-->
<Network>
<en_message>The one router got replaced and needs the correct IP-Addresses given to it.</en_message>
<fr_message>Le routeur a été remplacé et a besoin des adresses IP correctes qui lui ont été attribuées.</fr_message>
<en_message>The one router got replaced and needs the correct IP-Addresses and routes given to it.</en_message>
<fr_message>Le routeur a été remplacé et a besoin des adresses IP correctes qui lui ont été attribuées et des itinéraires.</fr_message>
<en_title>Router Replacement</en_title>
<height>1024</height>
<width>1024</width>
@ -1205,18 +1205,6 @@
ID="1">Untagged</VLAN>
</interface>
</nic>
<route>
<ip>172.16.1.2</ip>
<mask>255.255.255.252</mask>
<gateway>172.16.1.9</gateway>
<type>route</type>
</route>
<route>
<ip>172.16.1.18</ip>
<mask>255.255.255.252</mask>
<gateway>172.16.1.14</gateway>
<type>route</type>
</route>
</device>
<device>
<hostname>router4</hostname>

View File

@ -1478,6 +1478,11 @@ Someone is complaining that they cannot access the servers on the other side of
<dhost>pc3</dhost>
<thetest>SuccessfullyPings</thetest>
</nettest>
<nettest>
<shost>laptop0</shost>
<dhost>server0</dhost>
<thetest>NeedsLocalIPTo</thetest>
</nettest>
<VLANName
ID="1"
Color="Blue">Default</VLANName>

View File

@ -1102,6 +1102,6 @@ Ce puzzle a un interrupteur que vous avez été bloqué. Réinitialisez-le (clic
Color="Blue">Default</VLANName>
<VLANName
ID="2"
Color="Blue">Sttaff</VLANName>
Color="Blue">Staff</VLANName>
</Network>
</EduNetworkBuilder>

View File

@ -3,7 +3,7 @@
<!--This is a network file for EduNetworkBuilder.-->
<Network>
<en_message>Switch Ports can have three states:
Unagged
UnTagged
Tagged
Forbidden
When you are connecting switch-to-switch, they should be "Tagged." This makes a "Trunk", or a backbone link that can pass any VLAN. This allows packets to go to all the switches, and let the switches determine what devices they can go to from there.
@ -1124,6 +1124,6 @@ Pour compléter ce puzzle, vérifiez les deux commutateurs. L'un d'eux n'a pas l
Color="Blue">Default</VLANName>
<VLANName
ID="2"
Color="Blue">Sttaff</VLANName>
Color="Blue">Staff</VLANName>
</Network>
</EduNetworkBuilder>

View File

@ -2,7 +2,7 @@
<EduNetworkBuilder>
<!--This is a network file for EduNetworkBuilder.-->
<Network>
<en_message>A staff memner brought in a laptop and they have problems. As always, they want you to fix it.
<en_message>A staff member brought in a laptop and they have problems. As always, they want you to fix it.
Some vlan issues are a lot simpler than they originally look.</en_message>
<fr_message>Un membre du personnel a apporté un ordinateur portable et ils ont des problèmes. Comme toujours, ils veulent que vous le répariez.
Certains problèmes de vlan sont beaucoup plus simples qu'ils ne le paraissent à l'origine.</fr_message>

View File

@ -1204,6 +1204,6 @@
Color="Blue">Default</VLANName>
<VLANName
ID="2"
Color="Blue">Sttaff</VLANName>
Color="Blue">Staff</VLANName>
</Network>
</EduNetworkBuilder>

View File

@ -1214,6 +1214,6 @@ Pour que cela fonctionne, nous avons besoin de deux VLAN différents sur le seul
Color="Blue">Default</VLANName>
<VLANName
ID="2"
Color="Blue">Sttaff</VLANName>
Color="Blue">Staff</VLANName>
</Network>
</EduNetworkBuilder>

View File

@ -1121,6 +1121,6 @@ Faites un ping sur un certain nombre d'ordinateurs et faites des pings de diffus
Color="Blue">Default</VLANName>
<VLANName
ID="2"
Color="Blue">Sttaff</VLANName>
Color="Blue">Staff</VLANName>
</Network>
</EduNetworkBuilder>

View File

@ -42,6 +42,8 @@
<nictype>lo</nictype>
<uniqueidentifier>101</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -66,6 +68,8 @@
<nictype>wan</nictype>
<uniqueidentifier>104</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>wan0</nicname>
<myip>
@ -90,6 +94,8 @@
<nictype>eth</nictype>
<uniqueidentifier>102</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth0</nicname>
<myip>
@ -153,6 +159,8 @@
<nictype>eth</nictype>
<uniqueidentifier>103</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth1</nicname>
<myip>
@ -202,6 +210,8 @@
<nictype>lo</nictype>
<uniqueidentifier>106</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -226,6 +236,8 @@
<nictype>management_interface</nictype>
<uniqueidentifier>107</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>management_interface0</nicname>
<myip>
@ -250,6 +262,8 @@
<nictype>port</nictype>
<uniqueidentifier>108</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port1</nicname>
<myip>
@ -276,6 +290,8 @@
<nictype>port</nictype>
<uniqueidentifier>109</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port2</nicname>
<myip>
@ -302,6 +318,8 @@
<nictype>port</nictype>
<uniqueidentifier>110</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port3</nicname>
<myip>
@ -328,6 +346,8 @@
<nictype>port</nictype>
<uniqueidentifier>111</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port4</nicname>
<myip>
@ -354,6 +374,8 @@
<nictype>port</nictype>
<uniqueidentifier>112</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port5</nicname>
<myip>
@ -380,6 +402,8 @@
<nictype>port</nictype>
<uniqueidentifier>113</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port6</nicname>
<myip>
@ -410,6 +434,8 @@
<nictype>port</nictype>
<uniqueidentifier>114</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port7</nicname>
<myip>
@ -455,6 +481,8 @@
<nictype>lo</nictype>
<uniqueidentifier>116</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -479,6 +507,8 @@
<nictype>management_interface</nictype>
<uniqueidentifier>117</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>management_interface0</nicname>
<myip>
@ -505,6 +535,8 @@
<nictype>port</nictype>
<uniqueidentifier>118</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port1</nicname>
<myip>
@ -533,6 +565,8 @@
<nictype>port</nictype>
<uniqueidentifier>119</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port2</nicname>
<myip>
@ -542,11 +576,11 @@
<type>ip</type>
</myip>
<VLAN
ID="1">Untagged</VLAN>
ID="1">Forbidden</VLAN>
<VLAN
ID="2">Forbidden</VLAN>
<VLAN
ID="3">Forbidden</VLAN>
ID="3">Untagged</VLAN>
</interface>
</nic>
<nic>
@ -561,6 +595,8 @@
<nictype>port</nictype>
<uniqueidentifier>120</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port3</nicname>
<myip>
@ -589,6 +625,8 @@
<nictype>port</nictype>
<uniqueidentifier>121</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port4</nicname>
<myip>
@ -617,6 +655,8 @@
<nictype>port</nictype>
<uniqueidentifier>122</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port5</nicname>
<myip>
@ -645,6 +685,8 @@
<nictype>port</nictype>
<uniqueidentifier>123</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port6</nicname>
<myip>
@ -675,6 +717,8 @@
<nictype>port</nictype>
<uniqueidentifier>124</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port7</nicname>
<myip>
@ -720,6 +764,8 @@
<nictype>lo</nictype>
<uniqueidentifier>126</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -744,6 +790,8 @@
<nictype>management_interface</nictype>
<uniqueidentifier>127</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>management_interface0</nicname>
<myip>
@ -770,6 +818,8 @@
<nictype>port</nictype>
<uniqueidentifier>128</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port1</nicname>
<myip>
@ -798,6 +848,8 @@
<nictype>port</nictype>
<uniqueidentifier>129</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port2</nicname>
<myip>
@ -826,6 +878,8 @@
<nictype>port</nictype>
<uniqueidentifier>130</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port3</nicname>
<myip>
@ -852,6 +906,8 @@
<nictype>port</nictype>
<uniqueidentifier>131</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port4</nicname>
<myip>
@ -878,6 +934,8 @@
<nictype>port</nictype>
<uniqueidentifier>132</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port5</nicname>
<myip>
@ -904,6 +962,8 @@
<nictype>port</nictype>
<uniqueidentifier>133</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port6</nicname>
<myip>
@ -934,6 +994,8 @@
<nictype>port</nictype>
<uniqueidentifier>134</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>port7</nicname>
<myip>
@ -980,6 +1042,8 @@
<nictype>lo</nictype>
<uniqueidentifier>136</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -1004,6 +1068,8 @@
<nictype>eth</nictype>
<uniqueidentifier>137</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth0</nicname>
<myip>
@ -1044,6 +1110,8 @@
<nictype>lo</nictype>
<uniqueidentifier>139</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -1068,6 +1136,8 @@
<nictype>eth</nictype>
<uniqueidentifier>140</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth0</nicname>
<myip>
@ -1108,6 +1178,8 @@
<nictype>lo</nictype>
<uniqueidentifier>142</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -1132,6 +1204,8 @@
<nictype>eth</nictype>
<uniqueidentifier>143</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth0</nicname>
<myip>
@ -1172,6 +1246,8 @@
<nictype>lo</nictype>
<uniqueidentifier>145</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -1196,6 +1272,8 @@
<nictype>eth</nictype>
<uniqueidentifier>146</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth0</nicname>
<myip>
@ -1236,6 +1314,8 @@
<nictype>lo</nictype>
<uniqueidentifier>148</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -1260,6 +1340,8 @@
<nictype>eth</nictype>
<uniqueidentifier>149</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth0</nicname>
<myip>
@ -1300,6 +1382,8 @@
<nictype>lo</nictype>
<uniqueidentifier>151</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -1324,6 +1408,8 @@
<nictype>eth</nictype>
<uniqueidentifier>152</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth0</nicname>
<myip>
@ -1364,6 +1450,8 @@
<nictype>lo</nictype>
<uniqueidentifier>154</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>lo0</nicname>
<myip>
@ -1388,6 +1476,8 @@
<nictype>eth</nictype>
<uniqueidentifier>155</uniqueidentifier>
<usesdhcp>False</usesdhcp>
<encryptionkey />
<ssid />
<interface>
<nicname>eth0</nicname>
<myip>

View File

@ -2129,4 +2129,40 @@
<value>Regression testing</value>
<comment>LBW_Regression_Testing = Regression testing</comment>
</data>
<data name="IPE_GatewayTooltip" xml:space="preserve">
<value>This is the gateway to use on this network. If a device exists with this IP, that device will be set up as the gateway.</value>
<comment>IPE_GatewayTooltip = This is the gateway to use on this network. If a device exists with this IP, that device will be set up as the gateway.</comment>
</data>
<data name="IPE_NetmaskTooltip" xml:space="preserve">
<value>This is the netmask we are using when renumbering the subnet.</value>
<comment>IPE_NetmaskTooltip = This is the netmask we are using when renumbering the subnet.</comment>
</data>
<data name="IPE_Network" xml:space="preserve">
<value>Network</value>
<comment>IPE_Network = Network</comment>
</data>
<data name="IPE_NetworkTooltip" xml:space="preserve">
<value>This is the network address to use. The gateway should be part of this network.</value>
<comment>IPE_NetworkTooltip = This is the network address to use. The gateway should be part of this network.</comment>
</data>
<data name="NB_ChooseGateway" xml:space="preserve">
<value>Choose a gateway device</value>
<comment>NB_ChooseGateway = Choose a gateway device</comment>
</data>
<data name="NB_Renumber" xml:space="preserve">
<value>Renumber IPs</value>
<comment>NB_Renumber = Renumber IPs</comment>
</data>
<data name="NB_Subnet" xml:space="preserve">
<value>New Subnet</value>
<comment>NB_Subnet = New Subnet</comment>
</data>
<data name="NB_ChooseVLANRenumber" xml:space="preserve">
<value>What VLAN to renumber?</value>
<comment>NB_ChooseVLANRenumber = What VLAN to renumber?</comment>
</data>
<data name="NB_ChooseVLANRenumberTitle" xml:space="preserve">
<value>VLAN to renumber</value>
<comment>NB_ChooseVLANRenumberTitle = VLAN to renumber</comment>
</data>
</root>