Community discussions

MikroTik App
 
lucho512
just joined
Topic Author
Posts: 19
Joined: Tue Aug 17, 2010 12:21 am

API in Visual Basic 6 working fine!

Mon May 09, 2011 7:52 pm

hi forum, after much searching, I found an example for the management of the api in vb6 posted by Royce3, after some minor alterations to make to achieve it to work well, AUI I leave so they can experience and that You will not find any echo in vb6 to handle the api. I hope this will be useful, and discuss their progress, I keep working !!!..

Greetings.
You do not have the required permissions to view the files attached to this post.
 
SamWCL
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Mon Apr 20, 2009 1:18 pm
Location: Nelson, NZ

Re: API in Visual Basic 6 working fine!

Mon May 09, 2011 8:31 pm

good job!
 
inibir
Member Candidate
Member Candidate
Posts: 116
Joined: Thu Nov 25, 2010 2:25 pm
Location: lebanon
Contact:

Re: API in Visual Basic 6 working fine!

Tue Sep 06, 2011 10:32 am

its not work

his return this msg
(Connecting)
ws_Error: Connection is forcefully rejected
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26292
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: API in Visual Basic 6 working fine!

Tue Sep 06, 2011 11:55 am

its not work

his return this msg
(Connecting)
ws_Error: Connection is forcefully rejected

did you enable the API on RouterOS?
 
inibir
Member Candidate
Member Candidate
Posts: 116
Joined: Thu Nov 25, 2010 2:25 pm
Location: lebanon
Contact:

Re: API in Visual Basic 6 working fine!

Thu Sep 08, 2011 10:28 pm

took 9 months trying to fix it, I knew I had to do to enable the API

tanks normis
 
User avatar
kurei
just joined
Posts: 24
Joined: Tue Aug 11, 2009 9:29 am
Contact:

Re: API in Visual Basic 6 working fine!

Mon Oct 10, 2011 11:48 am

WORKS PERFECTLY !!!

I've learned java and VB.NET, but I think, I'm still loving this classic things.

Spend one year to make API in visual basic, but I got nothing. :lol:
 
User avatar
lucubrb
just joined
Posts: 2
Joined: Sat Nov 05, 2011 5:00 pm
Location: localhost - 127.0.0.1
Contact:

Re: API in Visual Basic 6 working fine!

Sat Nov 05, 2011 5:06 pm

its not work

his return this msg
(Connecting)
ws_Error: Connection is forcefully rejected
ip - service

did you enable api?

i used ros 5.8 and working properly.

Great job, TS.
 
DorisLam
just joined
Posts: 1
Joined: Wed Aug 31, 2011 12:34 am

Re: API in Visual Basic 6 working fine!

Thu Apr 12, 2012 3:16 pm

The script is working fine for me, the API is enabled and I can log in the router.

When I click SEND, I can see the same results. The probleme is when I click again on SEND, I get the OLD result + the new one. I cleared the text field before clicking SEND (txtout.text=""), but same problem. It seem the buffer is not clearing after the command is executed. I suspect the inbuf1 variable.


Thanks for your help
 
ax045Y
just joined
Posts: 8
Joined: Sat Apr 21, 2012 11:30 pm

Re: API in Visual Basic 6 working fine!

Sat Apr 21, 2012 11:33 pm

is this script run correcly at v 5.12?
 
lucho512
just joined
Topic Author
Posts: 19
Joined: Tue Aug 17, 2010 12:21 am

Re: API in Visual Basic 6 working fine!

Sun Apr 22, 2012 2:01 am

is this script run correcly at v 5.12?
Yes, working fine!!!
 
ax045Y
just joined
Posts: 8
Joined: Sat Apr 21, 2012 11:30 pm

Re: API in Visual Basic 6 working fine!

Tue Apr 24, 2012 9:25 pm

is this script run correcly at v 5.12?
Yes, working fine!!!
what wrong with mine?
its error when copile to make .exe file

Image
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: API in Visual Basic 6 working fine!

Tue Apr 24, 2012 11:55 pm

@ax045Y
Do not use Package and Deployment Wizard to compile project, use VB6 IDE 'File/Make...' command instead.
In this case compiler shows you what and where is wrong with code.
This API example works fine, problem is with 'CRAM_MD5' function in 'MD5.cls'.
Remove this function and you will be able to compile this example to .EXE.

HTH,
 
ax045Y
just joined
Posts: 8
Joined: Sat Apr 21, 2012 11:30 pm

Re: API in Visual Basic 6 working fine!

Thu Apr 26, 2012 1:21 pm

@ax045Y
Do not use Package and Deployment Wizard to compile project, use VB6 IDE 'File/Make...' command instead.
In this case compiler shows you what and where is wrong with code.
This API example works fine, problem is with 'CRAM_MD5' function in 'MD5.cls'.
Remove this function and you will be able to compile this example to .EXE.

HTH,
:D
thanks..
anyway i have new problem.
what command to enable user?

Image

hmm,,
so this api just can do 1 line command?
 
bastakboys
just joined
Posts: 1
Joined: Tue Oct 09, 2012 8:15 am

Re: API in Visual Basic 6 working fine!

Tue Oct 09, 2012 8:39 am

do you have a vb.net source
 
amongdota
just joined
Posts: 7
Joined: Thu Aug 22, 2013 11:51 am

Re: API in Visual Basic 6 working fine!

Thu Aug 22, 2013 12:31 pm

Thanx lucho512 good job
The script is working fine for me, the API is enabled and I can log in the router.

When I click SEND, I can see the same results. The probleme is when I click again on SEND, I get the OLD result + the new one. I cleared the text field before clicking SEND (txtout.text=""), but same problem. It seem the buffer is not clearing after the command is executed. I suspect the inbuf1 variable.


Thanks for your help
Doris, i have your problem also, and after a hours i got this

change this
Private Sub ws_DataArrival(ByVal sent$)
.
.
.
end sub
into this
Private Sub ws_DataArrival(ByVal bytesTotal As Long)
    If bErr Then Exit Sub
    Dim ar() As Byte, i&
    ReDim ar(0 To bytesTotal - 1)
    ws.GetData ar, vbByte, bytesTotal
    On Error Resume Next
    Err.Clear
    On Error GoTo 0
    inbuf1 = ar
    Dim WordLen&, StartIdx&, Idx&
    StartIdx = 0
    Do While True
        Idx = StartIdx
        WordLen = CalcWordLen(inbuf1, Idx)
        If WordLen < 0 Then
            Exit Do
        End If
        If WordLen = 0 Then
            SentenceArrived (inbuf2)
            inbuf2 = ""
        Else
            If inbuf1(Idx) = Asc("=") Then
                inbuf2 = inbuf2 & " "
            End If
            For i = 0 To WordLen - 1
                inbuf2 = inbuf2 & Chr(inbuf1(Idx + i))
            Next
        End If
        StartIdx = Idx + WordLen
    Loop
End Sub
that solve my problem,

and for good looking change this :
Private Sub SendCommand(ByVal sCmd$)
.
.
.
End Sub
into this
Private Sub SendCommand(ByVal sCmd$)
    Dim ar$(), i&, buf() As Byte
    Out Replace(sCmd, " ", vbCrLf )
    ar = Split(sCmd, " ")
    For i = 0 To UBound(ar)
        EncodeWord buf, ar(i)
    Next
    EncodeWord buf, ""
    If ws.State = sckConnected Then ws.SendData buf
End Sub
im working vb api to create and generate hotspot user, because with user manager maximal active session for lvl4 is 20, its better to use /ip/hotspot than /tool/user-manager, hotspot active user can up to 200,

wait for my next reply with full VB code for create user, im sory for my bad english, this is my firts post :D
 
amongdota
just joined
Posts: 7
Joined: Thu Aug 22, 2013 11:51 am

Re: API in Visual Basic 6 working fine!

Thu Aug 22, 2013 12:53 pm


thanks..
anyway i have new problem.
what command to enable user?
hmm,,
so this api just can do 1 line command?
no u can change a line white space, and read about api query here http://wiki.mikrotik.com/wiki/API#Query_word
 
drprotic
just joined
Posts: 2
Joined: Sat Feb 22, 2014 4:03 pm

Re: API in Visual Basic 6 working fine!

Sat Feb 22, 2014 4:05 pm

ax045Y wrote:

thanks..
anyway i have new problem.
what command to enable user?
hmm,,
so this api just can do 1 line command?

no u can change a line white space, and read about api query here http://wiki.mikrotik.com/wiki/API#Query_word



Its work

/ip/hotspot/user/add O =name=user1 O =password=111 O =limit-uptime=00:01:00
 
drprotic
just joined
Posts: 2
Joined: Sat Feb 22, 2014 4:03 pm

Re: API in Visual Basic 6 working fine!

Sat Feb 22, 2014 11:10 pm


thanks..
anyway i have new problem.
what command to enable user?
hmm,,
so this api just can do 1 line command?
no u can change a line white space, and read about api query here http://wiki.mikrotik.com/wiki/API#Query_word


Try this:
/ip/hotspot/user/add O =name=user1 O =password=111 O =limit-uptime=00:01:00
 
edilsonlsouza
just joined
Posts: 5
Joined: Tue Aug 05, 2014 8:03 pm

Re: API in Visual Basic 6 working fine!

Tue Aug 05, 2014 8:05 pm

Olá,

Using this program, which the command to remove a joined via IP and also how to add?
 
edilsonlsouza
just joined
Posts: 5
Joined: Tue Aug 05, 2014 8:03 pm

Re: API in Visual Basic 6 working fine!

Tue Aug 05, 2014 8:18 pm

Olá,

Using this program, which the command to remove a joined via IP and also how to add?

Obrigado!
 
edilsonlsouza
just joined
Posts: 5
Joined: Tue Aug 05, 2014 8:03 pm

Re: API in Visual Basic 6 working fine!

Wed Aug 06, 2014 4:26 pm

Olá,

Being ocorreno this error on the line below:
erro.png
erro2.png
Thanks in advance!
You do not have the required permissions to view the files attached to this post.
 
edilsonlsouza
just joined
Posts: 5
Joined: Tue Aug 05, 2014 8:03 pm

Re: API in Visual Basic 6 working fine!

Wed Aug 06, 2014 4:52 pm

Olá,

Being ocorreno this error on the line below:
erro.png
erro2.png
Thanks in advance!
I solved the problem:

Open your project.
Click the Project menu item, then select References...
From Available References, check the box next to Microsoft VBScript Regular Expressions 5.5, where n.n is one of the following:

Obrigado!!!
 
edilsonlsouza
just joined
Posts: 5
Joined: Tue Aug 05, 2014 8:03 pm

Re: API in Visual Basic 6 working fine!

Wed Aug 06, 2014 5:04 pm

I'm new and I'm learning with this API. Wanted to know what command to add, modify and remove a user on mikrotik.

Thank you!

My examples via SSH/New Terminal:

modify
/ip hotspot user set [/ip hotspot user find name=celular] profile=Debito
remove
/ip hotspot user remove [/ip hotspot user find address=200.189.23.202]
register / add
/ip hotspot user
add server=hotspot name=celular password=celular address=200.189.23.202 \
mac-address=bc:85:1f:d6:ac:3e profile=1024k disabled=no comment="EDILSON SOUZA - CELULAR, 3371-5090"
How is the command via API?

This system registers over a command line?

Thank you!
 
danieln
just joined
Posts: 3
Joined: Thu Apr 28, 2016 4:51 pm

Re: API in Visual Basic 6 working fine!

Mon May 16, 2016 7:56 pm

Hello friends. I have a question. anyone knows how to connect an api in VB a MikroTik by mac and not by ip?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API in Visual Basic 6 working fine!

Tue May 17, 2016 4:10 pm

API works only over TCP, it's not possible to use API over MAC connection
 
danieln
just joined
Posts: 3
Joined: Thu Apr 28, 2016 4:51 pm

Re: API in Visual Basic 6 working fine!

Sat May 21, 2016 12:44 am

API works only over TCP, it's not possible to use API over MAC connection
thanks, i have other concerns, how i can transfer files to routeros by api?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API in Visual Basic 6 working fine!

Sat May 21, 2016 5:11 pm

You cannot. RouterOS API still has 4kbytes limit on file size :)
Use ftp or scp for file transfer.
 
AboodSoft
just joined
Posts: 1
Joined: Mon May 02, 2016 6:31 pm

Re: API in Visual Basic 6 working fine!

Sun May 22, 2016 9:40 pm

Show how active users in datagrid
 
BaselMhmd
just joined
Posts: 1
Joined: Thu Mar 09, 2017 10:58 am

Re: API in Visual Basic 6 working fine!

Mon Mar 13, 2017 2:31 pm

How is the load profile in the list
 
paramex
just joined
Posts: 4
Joined: Tue Nov 14, 2017 9:36 pm

Re: API in Visual Basic 6 working fine!

Tue Nov 14, 2017 10:58 pm

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
    If bErr Then Exit Sub
    Dim ar() As Byte, i&
    ReDim ar(0 To bytesTotal - 1)
    ws.GetData ar, vbByte, bytesTotal
    On Error Resume Next
    Err.Clear
    On Error GoTo 0
    inbuf1 = ar
    Dim WordLen&, StartIdx&, Idx&
    StartIdx = 0
    Do While True
        Idx = StartIdx
        WordLen = CalcWordLen(inbuf1, Idx)
        If WordLen < 0 Then
            Exit Do
        End If
        If WordLen = 0 Then
            SentenceArrived (inbuf2)
            inbuf2 = ""
        Else
            If inbuf1(Idx) = Asc("=") Then
                inbuf2 = inbuf2 & " "
            End If
            For i = 0 To WordLen - 1
                inbuf2 = inbuf2 & Chr(inbuf1(Idx + i))
            Next
        End If
        StartIdx = Idx + WordLen
    Loop
End Sub
hi, i new member, thank for this script, but for me this one can't solve my problem.. :(, i try this work if i make a few users, but this not work for many users, i use v6.33 with 845 users. I can see the same results too, i find trouble like this :
1. normal - use a few user with user manager
Image ,
2. trouble line
Image

i guess this trouble in data arrival

send command script :
/tool/user-manager/user/print
sorry my english not good ...
thanks for help ..
 
paramex
just joined
Posts: 4
Joined: Tue Nov 14, 2017 9:36 pm

Re: API in Visual Basic 6 working fine!

Thu Nov 16, 2017 10:56 am

How is the load profile in the list
with user manager (userman)
SendCommand "/tool/user-manager/profile/print"
or with internal hotspot
SendCommand "/ip/hotspot/profile/print"
 
welovechonburi
just joined
Posts: 7
Joined: Sun Jul 31, 2016 12:04 pm

Re: API in Visual Basic 6 working fine!

Thu Jun 21, 2018 3:08 am

why command not work
i want to disable hotspot1 by vb6

ip/hotspot/set O =name=hotspot1 O =disabled=yes

thank you
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: API in Visual Basic 6 working fine!

Thu Jun 21, 2018 3:58 pm

Maybe, it should be "/ip/hotspot/set", not "ip/hotspot/set"?
 
dap1d5
just joined
Posts: 2
Joined: Sun May 03, 2020 9:15 am

Re: API in Visual Basic 6 working fine!

Sun May 03, 2020 10:48 am

Good day everyone.

Is it still working with routerOs firmware version 6.46.3. I got an error invalid username or password.

Anyone have update script for VB6 how to get login?

Thank in advance.
You do not have the required permissions to view the files attached to this post.
 
dap1d5
just joined
Posts: 2
Joined: Sun May 03, 2020 9:15 am

Re: API in Visual Basic 6 working fine!

Sun May 03, 2020 11:06 am

I already log in now, after read a topic here viewtopic.php?t=135808

Change this line:
tmp = "/login =name=" & txtUser.text & " =response=00" & tmp
Into this:
tmp = "/login =name=" & txtUser.text & " =password=" & txtPass.text
Thank you.
 
Proasg
just joined
Posts: 1
Joined: Mon Apr 29, 2019 11:49 am

Re: API in Visual Basic 6 working fine!

Sun May 02, 2021 12:20 pm

how organize in a datagrid or any where
 
agungsantoso
just joined
Posts: 1
Joined: Fri Feb 10, 2023 6:05 pm

Re: API in Visual Basic 6 working fine!

Sun Feb 12, 2023 3:00 am

I missing winsock, are you have the link it?

Who is online

Users browsing this forum: Google [Bot], JDF, RHWwijk and 89 guests