Пример использования SSH.NET библиотеки и mikrotik для занесение списка в ipset

C Sharp > Пример использования SSH.NET библиотеки и mikrotik для занесение списка в ipset
16.01.2018 18:03:23


Наиболее часто встречающиеся слова в статье:

[sshclient] [readText] [RunCommand] [firewall] [address-list] [address="] [install] [Install-Package] [-Version] [private]


Статья:

using Renci.SshNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace New_Dell_Spiski
{
    public partial class Form1 : Form
    {
        // install пакет SSH.NET Install-Package SSH.NET -Version 2016.1.0
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 
 
            // install пакет SSH.NET Install-Package SSH.NET -Version 2016.1.0
            string ip = "";
            string path = "noaccess.txt";
            string[] readText = File.ReadAllLines(path);
            using (var sshclient = new SshClient("192.168.1.1", "admin", "xcxssdd"))
            {
                sshclient.Connect();
                foreach (var x in readText)
                {
                    ip = x.Trim();
                    var cmd = sshclient.RunCommand("/ip firewall address-list add list=internet_time_limit timeout=20w address=" + ip );
                }
                sshclient.Disconnect();
            }
            //->>>>>>>>>
            MessageBox.Show("Адреса добавлены!", "Добавление IP в ");
 
        }
 
 
 
 
 
 
 
        private void button2_Click(object sender, EventArgs e)
        {
            // install пакет SSH.NET Install-Package SSH.NET -Version 2016.1.0
            string ip = "";
            string path = "noaccess.txt";
            string[] readText = File.ReadAllLines(path);
            using (var sshclient = new SshClient("192.168.1.1", "admin", "hjggtt55"))
            {
                sshclient.Connect();
                foreach (var x in readText)
                {
                    ip = x.Trim();
                    var cmd = sshclient.RunCommand("/ip firewall address-list remove [find where list=internet_time_limit && address=" + ip + "]");
                    var cmd2 = sshclient.RunCommand("/ip firewall address-list remove [find where list=internet && address=" + ip + "]");
                }
                sshclient.Disconnect();
            }
            //->>>>>>>>>
            MessageBox.Show("Адреса удалены!", "Добавление IP в ");
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            string ip = "";
            string path = "noaccess.txt";
            string[] readText = File.ReadAllLines(path);
            using (var sshclient = new SshClient("192.168.1.1", "admin", "ghhhkjy6"))
            {
                sshclient.Connect();
                foreach (var x in readText)
                {
                    ip = x.Trim();
                    var cmd = sshclient.RunCommand("/ip firewall address-list remove [find where list=internet_time_limit && address=" + ip + "]");
                    var cmd2 = sshclient.RunCommand("/ip firewall address-list add list=internet timeout=20w address=" + ip);
 
                }
                sshclient.Disconnect();
            }
            //->>>>>>>>>
            MessageBox.Show("Адреса удалены! и добавлены", "Добавление IP в ");
        }
    }
}