Ejemplo n.º 1
0
        private void MikrotikIPSecTunelsFlush_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                Thread runThread = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        #region Выполнение Flush

                        MK mikrotikIPSecFlush = new MK(SelectedIP.IPAddress);
                        if (!mikrotikIPSecFlush.Login(SelectedCredentials.Login, SelectedCredentials.Password))
                        {
                            Log("Could not log in");
                            mikrotikIPSecFlush.Close();
                            return;
                        }
                        mikrotikIPSecFlush.Send("/ip/ipsec/installed-sa/flush");
                        mikrotikIPSecFlush.Send("=sa-type=all");
                        mikrotikIPSecFlush.Send(".tag=flush", true);

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        Log(ex.Message);
                    }
                }));
                runThread.Start();
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void UsbPowerReset_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                Thread runThread = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        #region Сброс питания на USB порту MikroTik
                        int seconds = 5;
                        Dispatcher.Invoke(() =>
                        {
                            if (int.TryParse(((Button)e.OriginalSource).Tag.ToString(), out seconds))
                            {
                            }
                            else
                            {
                                seconds = 5;
                            }
                        });


                        MK mikrotikUSBPowerReset = new MK(SelectedIP.IPAddress);
                        if (!mikrotikUSBPowerReset.Login(SelectedCredentials.Login, SelectedCredentials.Password))
                        {
                            Log("Не удается подключиться к MikroTik");
                            mikrotikUSBPowerReset.Close();
                            return;
                        }
                        //system routerboard usb power-reset duration=5
                        mikrotikUSBPowerReset.Send("/system/routerboard/usb/power-reset");


                        mikrotikUSBPowerReset.Send($"=duration={seconds}");
                        mikrotikUSBPowerReset.Send(".tag=rebootUsb", true);
                        //mikrotik.Send(".tag=arp", true);
                        //Host curHost;
                        //StringBuilder result = new StringBuilder();
                        //foreach (string h in mikrotikUSBPowerReset.Read())
                        //{
                        //    result.AppendLine(h);
                        //}
                        //Console.Write(result.ToString());

                        //Console.ReadKey();
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        Log(ex.Message);
                    }
                }));
                runThread.Start();
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void MikrotikIPSecTunelsPrint_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                IP curIP = SelectedIP;

                Thread runThread = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        #region Вывод списка направлений туннеля
                        MK mikrotikIPSecTunels = new MK(curIP.IPAddress);
                        if (!mikrotikIPSecTunels.Login(SelectedCredentials.Login, SelectedCredentials.Password))
                        {
                            Log("Could not log in");
                            mikrotikIPSecTunels.Close();
                            return;
                        }
                        mikrotikIPSecTunels.Send("/ip/ipsec/installed-sa/print");
                        mikrotikIPSecTunels.Send(".tag=listInstalledSAs", true);
                        StringBuilder result = new StringBuilder();
                        //List<string[]> temp = new List<string[]>();
                        foreach (string h in mikrotikIPSecTunels.Read())
                        {
                            var massElements = h.Split('=');
                            if (massElements.Count() > 9)
                            {
                                result.AppendLine($"src-address {massElements[7]} ---> dst-address {massElements[9]}");
                            }
                        }
                        Dispatcher.Invoke(() =>
                        {
                            ((Button)e.OriginalSource).Tag = result;
                        });

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        Log(ex.Message);
                    }
                }));
                runThread.Start();
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }
            //StringBuilder test = new StringBuilder();
            //test.AppendLine($"src-address 192.168.61.102 ---> dst-address 8.8.8.8");
            //test.AppendLine($"src-address 8.8.8.8 ---> dst-address 192.168.61.102");
            //((Button)e.OriginalSource).Tag = test.ToString();
        }
Ejemplo n.º 4
0
        private void MikrotikIPSec_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                Thread runThread = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        #region Вывод списка каналов

                        MK mikrotikIPSec = new MK(SelectedIP.IPAddress);
                        if (!mikrotikIPSec.Login(SelectedCredentials.Login, SelectedCredentials.Password))
                        {
                            Log("Could not log in");
                            mikrotikIPSec.Close();
                            return;
                        }
                        mikrotikIPSec.Send("/ip/ipsec/policy/print");
                        mikrotikIPSec.Send(".tag=policies", true);
                        StringBuilder result = new StringBuilder();
                        foreach (string h in mikrotikIPSec.Read())
                        {
                            var massElements = h.Split('=');
                            if (massElements.Count() > 9)
                            {
                                foreach (var item in massElements)
                                {
                                    result.AppendLine(item);
                                }
                            }
                        }
                        Dispatcher.Invoke(() =>
                        {
                            ((Button)e.OriginalSource).Tag = result;
                        });

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        Log(ex.Message);
                    }
                }));
                runThread.Start();
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }
        }