Skip to content

VB trivial example

Daniel Frantik edited this page Apr 9, 2017 · 5 revisions

Full example from root page converted to VB.NET

  1. Add reference to tik4ne dlls/projects/packages (tik4net.dll, tik4net.objects.dll)
  2. Replace HOST, USER and PASS by your real credentials.
  3. Try the example:
Imports tik4net
Imports tik4net.Objects
Imports tik4net.Objects.Ip.Firewall

Namespace Test
   Public Class MyTest
      Public Sub TestMikrotik()   
         Using connection As ITikConnection = ConnectionFactory.CreateConnection(TikConnectionType.Api)
            connection.Open(HOST, USER, PASS)

            Dim cmd As ITikCommand = connection.CreateCommand("/system/identity/print")
            Dim identity = cmd.ExecuteScalar()
            Console.WriteLine("Identity: {0}", identity)

            Dim logs = connection.LoadList(Of Log)()
            For Each log As Log In logs
               Console.WriteLine("{0}[{1}]: {2}", log.Time, log.Topics, log.Message)
            Next

            Dim firewallFilter = New FirewallFilter() With { _
               Key .Chain = FirewallFilter.ChainType.Forward, _
               Key .Action = FirewallFilter.ActionType.Accept _
            }
            connection.Save(firewallFilter)
         End Using
      End Sub
   End Class
End Namespace
Clone this wiki locally