public static void FillRouteTable() { adapters = new AdaptersTable(); iph = new IPHelper(adapters); interfaceInfo = iph.GetInterfacesIP(); GetPersistentRoutes(); _routesTableEntries = iph.GetRoutesTable(); routeTable.Clear(); for (int x = 0; x <= _routesTableEntries.Count - 1; x++) { routeTable.Rows.Add(); routeTable.Rows[routeTable.Rows.Count - 1][0] = _routesTableEntries[x].Destination; routeTable.Rows[routeTable.Rows.Count - 1][1] = _routesTableEntries[x].Mask; routeTable.Rows[routeTable.Rows.Count - 1][2] = _routesTableEntries[x].NextHop; routeTable.Rows[routeTable.Rows.Count - 1][3] = _routesTableEntries[x].Index; routeTable.Rows[routeTable.Rows.Count - 1][4] = _routesTableEntries[x].ForwardType; routeTable.Rows[routeTable.Rows.Count - 1][5] = _routesTableEntries[x].ForwardType; routeTable.Rows[routeTable.Rows.Count - 1][6] = _routesTableEntries[x].Protocol; routeTable.Rows[routeTable.Rows.Count - 1][7] = _routesTableEntries[x].Protocol; routeTable.Rows[routeTable.Rows.Count - 1][8] = _routesTableEntries[x].Age; routeTable.Rows[routeTable.Rows.Count - 1][9] = _routesTableEntries[x].Metric1; InterfaceIPEntry inter = GetInterfaceByID(_routesTableEntries[x].Index); if (inter != null) { routeTable.Rows[routeTable.Rows.Count - 1][10] = inter.InterfaceDescription; } else { MessageBox.Show("sdfgdfgfg"); } routeTable.Rows[routeTable.Rows.Count - 1][11] = TimeSpan.FromSeconds(_routesTableEntries[x].Age); routeTable.Rows[routeTable.Rows.Count - 1][12] = Convert.ToString(x + 1); routeTable.Rows[routeTable.Rows.Count - 1][13] = Convert.ToString("Нет"); if (persistentRoutes.Length - 1 >= 0) { bool find = false; for (int y = 0; y <= persistentRoutes.Length - 1; y++) { if (_routesTableEntries[x].Destination.ToString() == persistentRoutes[y].dest) { if (_routesTableEntries[x].Mask.ToString() == persistentRoutes[y].mask) { if (_routesTableEntries[x].NextHop.ToString() == persistentRoutes[y].hop) { routeTable.Rows[routeTable.Rows.Count - 1][13] = Convert.ToString("Да"); find = true; } } } if (!find) { routeTable.Rows[routeTable.Rows.Count - 1][13] = Convert.ToString("Нет"); } } } } }
public static void Init() { adapters = new AdaptersTable(); iph = new IPHelper(adapters); _routesTableEntries = iph.GetRoutesTable(); interfaceInfo = iph.GetInterfacesIP(); routeTable = new DataTable(); routeTable.Columns.Add("DestIP", System.Type.GetType("System.String")); routeTable.Columns.Add("SubnetMask", System.Type.GetType("System.String")); routeTable.Columns.Add("NextHop", System.Type.GetType("System.String")); routeTable.Columns.Add("IfIndex", System.Type.GetType("System.Int32")); routeTable.Columns.Add("Type", System.Type.GetType("System.Int32")); routeTable.Columns.Add("TypeText", System.Type.GetType("System.String")); routeTable.Columns.Add("Proto", System.Type.GetType("System.Int32")); routeTable.Columns.Add("ProtoText", System.Type.GetType("System.String")); routeTable.Columns.Add("Age", System.Type.GetType("System.Int32")); routeTable.Columns.Add("Metric1", System.Type.GetType("System.Int32")); routeTable.Columns.Add("IFText", System.Type.GetType("System.String")); routeTable.Columns.Add("AgeText", System.Type.GetType("System.String")); routeTable.Columns.Add("N", System.Type.GetType("System.Int32")); routeTable.Columns.Add("Persistent", System.Type.GetType("System.String")); }