Ejemplo n.º 1
0
        void clickedOff(System.Object sender, System.EventArgs e)
        {
            try
            {
                using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
                {
                    connection.Open(ipAdress(), Login.Text, Password.Text);
                    ITikCommand cmd = connection.CreateCommand("/system/identity/print");
                    Console.WriteLine(cmd.ExecuteScalar());
                    var poe = connection.CreateCommand("/interface/ethernet/set");

                    foreach (string i in OptionsPage.numbers)
                    {
                        int numPort = Int32.Parse(i);
                        poe.AddParameter(TikSpecialProperties.Id, ports[numPort - 1]);
                        poe.AddParameter("poe-out", "off");
                        poe.AddParameter("disabled", "yes");
                        //Console.WriteLine("ports: " + ports[numPort]);
                        poe.ExecuteNonQuery();
                    }
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        public static bool suspendpppoeuser(string pppoeuser)
        {
            using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api)) // Use TikConnectionType.Api for mikrotikversion prior v6.45
            {
                connection.Open("10.19.10.1", "OrionAdmin", "Frank1e2015");


                var pppoeactive = connection.LoadList <PppActive>();
                foreach (PppActive pppa in pppoeactive)
                {
                    string ipaddress = "";
                    if (pppa.Name == pppoeuser)
                    {
                        ipaddress = pppa.Address;
                    }
                    if (ipaddress != "")
                    {
                        ITikCommand cmd = connection.CreateCommand("/ip/firewall/address-list/add",
                                                                   connection.CreateParameter("list", "unmssuspend"),
                                                                   connection.CreateParameter("address", ipaddress),
                                                                   connection.CreateParameter("comment", "suspend"));
                        cmd.ExecuteAsync(response =>
                        {
                            // Console.WriteLine("Row: " + response.GetResponseField("tx"));
                        });

                        cmd.Cancel();
                    }
                }

                connection.Close();
            }
            return(true);
        }
Ejemplo n.º 3
0
        internal static List <MikrotikUserList> GetUserListFromMikrotik(ITikConnection connection, Mikrotik mikrotik)
        {
            List <MikrotikUserList> lstMikrotikUserList = new List <MikrotikUserList>();
            ITikCommand             userCmd             = connection.CreateCommand("/ppp/secret/print");
            var lstUserFromMikrotik = userCmd.ExecuteList();

            foreach (var user in lstUserFromMikrotik)
            {
                var name     = user.Words["name"];
                var password = user.Words["password"];
                var package  = user.Words["profile"];
                var active   = user.Words["disabled"];
                var profile  = user.Words["profile"];
                lstMikrotikUserList.Add(new MikrotikUserList()
                {
                    UserName     = name,
                    Password     = password,
                    MikrotikID   = mikrotik.MikrotikID,
                    MikrotikName = mikrotik.MikName,
                    ProfileName  = profile,
                    active       = active
                });
            }
            return(lstMikrotikUserList);
        }
Ejemplo n.º 4
0
        private static ITikCommand CreateLoadCommandWithFilter <TEntity> (ITikConnection connection, ITikCommandParameter[] parameters)
        {
            var metadata = TikEntityMetadataCache.GetMetadata <TEntity>();

            ITikCommand command = connection.CreateCommand(metadata.EntityPath + metadata.LoadCommand, metadata.LoadDefaultParameneterFormat);

            // =detail=
            if (metadata.IncludeDetails)
            {
                command.AddParameter("detail", "", TikCommandParameterFormat.NameValue);
            }
            //.proplist
            if (metadata.IncludeProplist)
            {
                command.AddParameter(TikSpecialProperties.Proplist, string.Join(",", metadata.Properties.Select(prop => prop.FieldName).ToArray()), TikCommandParameterFormat.NameValue);
            }
            //filter
            //parameters
            if (parameters != null)
            {
                foreach (ITikCommandParameter param in parameters)
                {
                    command.Parameters.Add(param);
                }
            }

            return(command);
        }
Ejemplo n.º 5
0
        private static void WriteToLog(ITikConnection connection, string message, string logLevelCommandSufix)
        {
            var cmd = connection.CreateCommand("/log/" + logLevelCommandSufix,
                                               connection.CreateParameter("message", message));

            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 6
0
 private void materialFlatButton1_Click(object sender, EventArgs e)
 {
     using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
     {
         connection.Open("192.168.0.1", "admin", "yami_yonatan");
         ITikCommand cmd = connection.CreateCommand("ip/neighbor/print");
         MessageBox.Show(cmd.ExecuteScalar());
     }
 }
Ejemplo n.º 7
0
        private static void Identity(ITikConnection connection)
        {
            ITikCommand cmd      = connection.CreateCommand("/system/identity/print");
            var         identity = cmd.ExecuteScalar(); //cmd.ExecuteSIngleRow()

            Console.WriteLine("Identity: " + /*identity.GetResponseField("name")*/ identity);

            Console.WriteLine("Press ENTER");
            Console.ReadLine();
        }
Ejemplo n.º 8
0
 public Task <bool> ActivateUser(UserManagerUser user, string profileName) => Task.Run(() =>
 {
     try
     {
         _connection.CreateCommand("/tool/user-manager/user/create-and-activate-profile", _connection.CreateParameter("user", user.Name), _connection.CreateParameter("customer", user.Customer), _connection.CreateParameter("profile", profileName)).ExecuteAsync(null);
         return(true);
     }
     catch
     {
         return(false);
     }
 });
Ejemplo n.º 9
0
 /// <summary>
 /// Called when the package is started.
 /// </summary>
 public override void OnStart()
 {
     Task.Factory.StartNew(async() =>
     {
         while (PackageHost.IsRunning)
         {
             try
             {
                 if (this.connection == null || !this.connection.IsOpened)
                 {
                     this.connection = this.GetConnection();
                 }
                 if (this.connection != null && this.connection.IsOpened)
                 {
                     try
                     {
                         // Test connection with simple command
                         connection.CreateCommand("/system/identity/print").ExecuteScalar();
                         // Query & push
                         // - Base objects -
                         this.QueryAndPush("SystemResource", () => connection.LoadSingle <SystemResource>());
                         this.QueryAndPush("Interfaces", () => connection.LoadList <Interface>());
                         this.QueryAndPush("IpAddresses", () => connection.LoadList <IpAddress>());
                         this.QueryAndPush("Pools", () => connection.LoadList <IpPool>());
                         this.QueryAndPush("Queues", () => connection.LoadList <QueueSimple>());
                         // - DHCP client & server leases -
                         this.QueryAndPush("DhcpClient", () => connection.LoadList <IpDhcpClient>());
                         this.QueryAndPush("DhcpServerLeases", () => connection.LoadList <DhcpServerLease>());
                         // - IPv6 objects -
                         this.QueryAndPush("Ipv6Neighbors", () => connection.LoadList <Ipv6Neighbor>());
                         this.QueryAndPush("Ipv6Pools", () => connection.LoadList <Ipv6Pool>());
                         this.QueryAndPush("Ipv6Addresses", () => connection.LoadList <Ipv6Address>());
                         this.QueryAndPush("Ipv6DhcpClient", () => connection.LoadList <Ipv6DhcpClient>());
                         // - CAPSMAN registration table  -
                         this.QueryAndPush("WirelessClients", () => connection.LoadList <CapsManRegistrationTable>());
                     }
                     catch (IOException)
                     {
                         this.connection = null;
                     }
                 }
                 await Task.Delay(Math.Min(1000, PackageHost.GetSettingValue <int>("QueryInterval")));
             }
             catch (Exception ex)
             {
                 PackageHost.WriteError($"Fatal error in the main loop : {ex}");
                 await Task.Delay(5000);
             }
         }
     }, TaskCreationOptions.LongRunning);
     PackageHost.WriteInfo("Package started !");
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Called when the package is started.
        /// </summary>
        public override void OnStart()
        {
            DateTime lastQuery = DateTime.MinValue;
            Thread   thQuery   = new Thread(new ThreadStart(() =>
            {
                while (PackageHost.IsRunning)
                {
                    if (DateTime.Now.Subtract(lastQuery).TotalMilliseconds >= PackageHost.GetSettingValue <int>("QueryInterval"))
                    {
                        if (this.connection == null || !this.connection.IsOpened)
                        {
                            this.connection = this.GetConnection();
                        }
                        if (this.connection != null && this.connection.IsOpened)
                        {
                            try
                            {
                                // Test connection with simple command
                                connection.CreateCommand("/system/identity/print").ExecuteScalar();
                                // Query & push
                                // - Base objects -
                                this.QueryAndPush("SystemResource", () => connection.LoadSingle <SystemResource>());
                                this.QueryAndPush("Interfaces", () => connection.LoadList <Interface>());
                                this.QueryAndPush("IpAddresses", () => connection.LoadList <IpAddress>());
                                this.QueryAndPush("Pools", () => connection.LoadList <IpPool>());
                                this.QueryAndPush("Queues", () => connection.LoadList <QueueSimple>());
                                // - DHCP client & server leases -
                                this.QueryAndPush("DhcpClient", () => connection.LoadList <IpDhcpClient>());
                                this.QueryAndPush("DhcpServerLeases", () => connection.LoadList <DhcpServerLease>());
                                // - IPv6 objects -
                                this.QueryAndPush("Ipv6Neighbors", () => connection.LoadList <Ipv6Neighbor>());
                                this.QueryAndPush("Ipv6Pools", () => connection.LoadList <Ipv6Pool>());
                                this.QueryAndPush("Ipv6Addresses", () => connection.LoadList <Ipv6Address>());
                                this.QueryAndPush("Ipv6DhcpClient", () => connection.LoadList <Ipv6DhcpClient>());
                                // - CAPSMAN registration table  -
                                this.QueryAndPush("WirelessClients", () => connection.LoadList <CapsManRegistrationTable>());
                            }
                            catch (IOException)
                            {
                                this.connection = null;
                            }
                        }
                        lastQuery = DateTime.Now;
                    }
                    Thread.Sleep(100);
                }
            }));

            thQuery.Start();
            PackageHost.WriteInfo("Package started !");
        }
Ejemplo n.º 11
0
        public static bool Mikrotik()

        {
            using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api)) // Use TikConnectionType.Api for mikrotikversion prior v6.45
            {
                connection.Open("10.19.20.1", "OrionAdmin", "Frank1e2015");
                ITikCommand cmd      = connection.CreateCommand("/system/identity/print");
                var         identity = cmd.ExecuteScalar();
                Console.WriteLine("Identity: {0}", identity);
                var logs = connection.LoadList <Log>();
                foreach (Log log in logs)
                {
                    Console.WriteLine("{0}[{1}]: {2}", log.Time, log.Topics, log.Message);
                }
                var firewallFilter = new FirewallFilter()
                {
                    Chain  = FirewallFilter.ChainType.Forward,
                    Action = FirewallFilter.ActionType.Accept,
                };
                connection.Save(firewallFilter);
                ITikCommand torchCmd = connection.CreateCommand("/tool/torch",
                                                                connection.CreateParameter("interface", "ether1"),
                                                                connection.CreateParameter("port", "any"),
                                                                connection.CreateParameter("src-address", "0.0.0.0/0"),
                                                                connection.CreateParameter("dst-address", "0.0.0.0/0"));

                torchCmd.ExecuteAsync(response =>
                {
                    Console.WriteLine("Row: " + response.GetResponseField("tx"));
                });
                Console.WriteLine("Press ENTER");
                Console.ReadLine();
                torchCmd.Cancel();
                return(true);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds a certain profile
        /// </summary>
        /// <param name="profile">The profile to add</param>
        /// <returns>The status of the adding process</returns>
        public Task <bool> AddProfileAsync(HotspotUserProfile profile) => Task.Run(() =>
        {
            try
            {
                //_connection.Save(profile);
                _connection.CreateCommand("/ip/hotspot/user/profile/add",
                                          _connection.CreateParameter("name", profile.Name),
                                          _connection.CreateParameter("shared-users", profile.SharedUsers),
                                          _connection.CreateParameter("rate-limit", profile.RateLimit)
                                          ).ExecuteNonQuery();

                return(true);
            }
            catch { return(false); }
        });
Ejemplo n.º 13
0
        internal static List <MikrotikUserList> GetActiveUserListFromMikrotik(ITikConnection connection, Mikrotik mikrotik)
        {
            List <MikrotikUserList> lstMikrotikUserList = new List <MikrotikUserList>();
            ITikCommand             userCmd             = connection.CreateCommand("/ppp/active/print");
            var lstUserFromMikrotik = userCmd.ExecuteList();

            foreach (var user in lstUserFromMikrotik)
            {
                var name = user.Words["name"];
                lstMikrotikUserList.Add(new MikrotikUserList()
                {
                    UserName = name
                });
            }
            return(lstMikrotikUserList);
        }
Ejemplo n.º 14
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            btnGenerate.Enabled = false;
            try
            {
                using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
                {
                    connection.Open(tbHost.Text, tbUser.Text, tbPass.Text);

                    var cmd = connection.CreateCommand(tbPath.Text);
                    if (cbIncludeDetails.Checked)
                    {
                        cmd.AddParameter("detail", "");
                    }
                    if (!string.IsNullOrWhiteSpace(tbParameters.Text))
                    {
                        cmd.AddParameterAndValues(tbParameters.Text.Split(';', '|'));
                    }

                    List <ITikReSentence> rows;
                    if (!cbExecuteAsync.Checked)
                    {
                        rows = cmd.ExecuteList().ToList();
                    }
                    else
                    {
                        rows = cmd.ExecuteListWithDuration(10).ToList();
                    }

                    if (rows.Any())
                    {
                        tbSourceCode.Text = Generate(tbPath.Text, cbIncludeDetails.Checked, rows);
                        tbSourceCode.SelectAll();
                        tbSourceCode.Focus();
                    }
                    else
                    {
                        MessageBox.Show("Empty response");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            btnGenerate.Enabled = true;
        }
Ejemplo n.º 15
0
        private static void Torch(ITikConnection connection)
        {
            ITikCommand torchCmd = connection.CreateCommand("/tool/torch",
                                                            connection.CreateParameter("interface", "ether1"),
                                                            connection.CreateParameter("port", "any"),
                                                            connection.CreateParameter("src-address", "0.0.0.0/0"),
                                                            connection.CreateParameter("dst-address", "0.0.0.0/0")
                                                            );

            torchCmd.ExecuteAsync(response =>
            {
                Console.WriteLine("Row: " + response.GetResponseField("tx"));
            });
            Console.WriteLine("Press ENTER");
            Console.ReadLine();
            torchCmd.CancelAndJoin();
        }
Ejemplo n.º 16
0
 void ButtonClickedConnect(System.Object sender, System.EventArgs e)
 {
     try
     {
         using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
         {
             connection.Open(ipAdress(), Login.Text, Password.Text);
             ITikCommand cmd = connection.CreateCommand("/system/identity/print");
             Console.WriteLine(cmd.ExecuteScalar());
             if (connection.IsOpened)
             {
                 ConnectionStatus.Text   = "OK";
                 buttonOn.IsVisible      = true;
                 buttonOff.IsVisible     = true;
                 ToOptionsPage.IsVisible = true;
                 buttonClear.Text        = "CANCEL";
                 IP_adress_1.IsEnabled   = false;
                 IP_adress_2.IsEnabled   = false;
                 IP_adress_3.IsEnabled   = false;
                 IP_adress_4.IsEnabled   = false;
                 Login.IsEnabled         = false;
                 Password.IsEnabled      = false;
                 buttonConnect.IsEnabled = false;
                 var poe_status = connection.LoadList <InterfaceEthernet>();
                 int portNum    = 0;
                 foreach (InterfaceEthernet interfaceEthernet in poe_status)
                 {
                     ports.Add(portNum, interfaceEthernet.Name);
                     portNum++;
                 }
                 //Console.WriteLine("Имя порта ", ports[0]); // имя порта
                 Console.WriteLine(ports.Keys.Count); // количество портов
             }
         }
     }
     catch (Exception ex)
     {
         //Console.WriteLine("Exception: " + ex.Message);
         ConnectionStatus.Text = ex.Message;
     }
 }
Ejemplo n.º 17
0
        public static bool UpdateSecret()
        {
            using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api)) // Use TikConnectionType.Api for mikrotikversion prior v6.45
            {
                connection.Open("10.19.60.1", "OrionAdmin", "Frank1e2015");

                radiusEntities     db            = new radiusEntities();
                List <RadiusEntry> radiusentries = db.RadiusEntries.ToList();
                foreach (RadiusEntry re in radiusentries)
                {
                    ITikCommand cmd = connection.CreateCommand("/ppp/secret/add",
                                                               connection.CreateParameter("name", re.username),
                                                               connection.CreateParameter("password", re.value),
                                                               connection.CreateParameter("profile", re.groupname));
                    cmd.ExecuteAsync(response =>
                    {
                        // Console.WriteLine("Row: " + response.GetResponseField("tx"));
                    });

                    cmd.Cancel();
                }
                return(true);
            }
        }
Ejemplo n.º 18
0
            /// <summary>
            /// Take new snapshot
            /// </summary>
            /// <param name="connection"></param>
            public static void Take(ITikConnection connection)
            {
                var cmd = connection.CreateCommand("/ip/accounting/snapshot/take");

                cmd.ExecuteNonQuery();
            }
Ejemplo n.º 19
0
        internal static IEnumerable <ITikReSentence> GetPackageListFromMikrotik(ITikConnection connection)
        {
            ITikCommand PackageCmd = connection.CreateCommand("/ppp/profile/print");

            return(PackageCmd.ExecuteList());
        }
Ejemplo n.º 20
0
Archivo: Log.cs Proyecto: h44z/tik4net
 private static void WriteToLog(ITikConnection connection, string message, string logLevelCommandSufix)
 {
     var cmd =connection.CreateCommand("/log/" + logLevelCommandSufix,
         connection.CreateParameter("message", message));
     cmd.ExecuteNonQuery();
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Take new snapshot
 /// </summary>
 /// <param name="connection"></param>
 public static void Take(ITikConnection connection)
 {
     var cmd = connection.CreateCommand("/ip/accounting/snapshot/take");
     cmd.ExecuteNonQuery();
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Executes given <paramref name="commandText"/> on router and ensures that operation returns one value (=ret parameter), which is returned as result.
        /// </summary>
        /// <param name="connection">Tik connection used to load.</param>
        /// <param name="commandText">Command text</param>
        /// <param name="parameters">Optional list of parameters</param>
        /// <returns>Value returned by router.</returns>
        public static string ExecuteScalar(this ITikConnection connection, string commandText, params ITikCommandParameter[] parameters)
        {
            var command = connection.CreateCommand(commandText, parameters);

            return(command.ExecuteScalar());
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Excecutes given <paramref name="commandText"/> on router and ensures that operation was sucessfull.
        /// </summary>
        /// <param name="connection">Tik connection used to load.</param>
        /// <param name="commandText">Command text</param>
        /// <param name="parameters">Optional list of parameters</param>
        public static void ExecuteNonQuery(this ITikConnection connection, string commandText, params ITikCommandParameter[] parameters)
        {
            var command = connection.CreateCommand(commandText, parameters);

            command.ExecuteNonQuery();
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Saves entity to mikrotik router. Does insert (/add) whan entity has empty id and update(/set + /unset) when id is present).
        /// Behavior of save is modified via <see cref="TikPropertyAttribute"/> on properties.
        /// See <see cref="TikPropertyAttribute.DefaultValue"/>, <see cref="TikPropertyAttribute.UnsetOnDefault"/>.
        /// </summary>
        /// <typeparam name="TEntity">Saved entitie type.</typeparam>
        /// <param name="connection">Tik connection used to save.</param>
        /// <param name="entity">Saved entity.</param>
        /// <param name="usedFieldsFilter">List of field names (on mikrotik) which should be modified. If is not null, only listed fields will be modified.</param>
        public static void Save <TEntity>(this ITikConnection connection, TEntity entity, IEnumerable <string> usedFieldsFilter = null)
            where TEntity : new()
        {
            var metadata = TikEntityMetadataCache.GetMetadata <TEntity>();

            EnsureNotReadonlyEntity(metadata);

            string id;

            if (metadata.IsSingleton)
            {
                id = null;
            }
            else
            {
                EnsureHasIdProperty(metadata);
                id = metadata.IdProperty.GetEntityValue(entity);
            }

            if (!metadata.IsSingleton && string.IsNullOrEmpty(id))
            {
                //create
                ITikCommand createCmd = connection.CreateCommand(metadata.EntityPath + "/add", TikCommandParameterFormat.NameValue);

                foreach (var property in metadata.Properties
                         .Where(pm => !pm.IsReadOnly)
                         .Where(pm => usedFieldsFilter == null || usedFieldsFilter.Contains(pm.FieldName, StringComparer.OrdinalIgnoreCase)))
                {
                    if (!property.HasDefaultValue(entity))
                    {
                        createCmd.AddParameter(property.FieldName, property.GetEntityValue(entity));
                    }
                }

                id = createCmd.ExecuteScalar();
                if (metadata.HasIdProperty)
                {
                    metadata.IdProperty.SetEntityValue(entity, id); // update saved id into entity
                }
            }
            else
            {
                //update (set+unset)
                ITikCommand setCmd = connection.CreateCommand(metadata.EntityPath + "/set", TikCommandParameterFormat.NameValue);

                if (!metadata.IsSingleton && usedFieldsFilter == null)
                {
                    //compare state on mikrotik and update different fields only
                    var unmodifiedEntity = connection.LoadById <TEntity>(id); //TODO some kind of "loaded entities" session cache could be used to avoid another load before save.
                    usedFieldsFilter = entity.GetDifferentFields(unmodifiedEntity);
                }

                List <string> fieldsToUnset = new List <string>();

                foreach (var property in metadata.Properties
                         .Where(pm => !pm.IsReadOnly)
                         .Where(pm => usedFieldsFilter == null || usedFieldsFilter.Contains(pm.FieldName, StringComparer.OrdinalIgnoreCase)))
                {
                    if (property.HasDefaultValue(entity) && property.UnsetOnDefault)
                    {
                        fieldsToUnset.Add(property.FieldName);
                    }
                    else
                    {
                        setCmd.AddParameter(property.FieldName, property.GetEntityValue(entity)); //full update (all values)
                    }
                }

                if (fieldsToUnset.Count > 0)
                {
                    // this should also work (see http://forum.mikrotik.com/viewtopic.php?t=28821 )
                    //ip/route/unset
                    //=.id = *1
                    //= value-name=routing-mark

                    foreach (string fld in fieldsToUnset)
                    {
                        ITikCommand unsetCmd = connection.CreateCommand(metadata.EntityPath + "/unset", TikCommandParameterFormat.NameValue);
                        unsetCmd.AddParameter(TikSpecialProperties.Id, id, TikCommandParameterFormat.NameValue);
                        unsetCmd.AddParameter(TikSpecialProperties.UnsetValueName, fld);

                        unsetCmd.ExecuteNonQuery();
                    }
                }
                if (setCmd.Parameters.Any())
                {
                    if (!metadata.IsSingleton)
                    {
                        setCmd.AddParameter(TikSpecialProperties.Id, id, TikCommandParameterFormat.NameValue);
                    }
                    setCmd.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 25
0
 /// <summary>
 /// clears internal DNS cache
 /// </summary>
 public void Flush(ITikConnection connection)
 {
     connection.CreateCommand("ip/dns/cache/flush").ExecuteNonQuery();
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Takes new accounting snapshot (/ip/accounting/snapshot/take)
        /// </summary>
        public static void FlushDnsCache(this ITikConnection connection)
        {
            var cmd = connection.CreateCommand("ip/dns/cache/flush");

            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 27
0
        private static void Identity(ITikConnection connection)
        {
            ITikCommand cmd = connection.CreateCommand("/system/identity/print");
            var identity = cmd.ExecuteScalar(); //cmd.ExecuteSIngleRow()
            Console.WriteLine("Identity: " + /*identity.GetResponseField("name")*/ identity);

            Console.WriteLine("Press ENTER");
            Console.ReadLine();
        }
Ejemplo n.º 28
0
 private static void Torch(ITikConnection connection)
 {
     ITikCommand torchCmd = connection.CreateCommand("/tool/torch",
         connection.CreateParameter("interface", "ether1"),
         connection.CreateParameter("port", "any"),
         connection.CreateParameter("src-address", "0.0.0.0/0"),
         connection.CreateParameter("dst-address", "0.0.0.0/0")
         );
     torchCmd.ExecuteAsync(response =>
     {
         Console.WriteLine("Row: " + response.GetResponseField("tx"));
     });
     Console.WriteLine("Press ENTER");
     Console.ReadLine();
     torchCmd.CancelAndJoin();
 }
Ejemplo n.º 29
0
 /// <summary>
 /// clears internal DNS cache 
 /// </summary>
 public void Flush(ITikConnection connection)
 {
     connection.CreateCommand("ip/dns/cache/flush").ExecuteNonQuery();
 }