Page 1 of 1

API in Visual Basic 6 working fine!

Posted: Mon May 09, 2011 7:52 pm
by lucho512
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.

Re: API in Visual Basic 6 working fine!

Posted: Mon May 09, 2011 8:31 pm
by SamWCL
good job!

Re: API in Visual Basic 6 working fine!

Posted: Tue Sep 06, 2011 10:32 am
by inibir
its not work

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

Re: API in Visual Basic 6 working fine!

Posted: Tue Sep 06, 2011 11:55 am
by normis
its not work

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

did you enable the API on RouterOS?

Re: API in Visual Basic 6 working fine!

Posted: Thu Sep 08, 2011 10:28 pm
by inibir
took 9 months trying to fix it, I knew I had to do to enable the API

tanks normis

Re: API in Visual Basic 6 working fine!

Posted: Mon Oct 10, 2011 11:48 am
by kurei
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:

Re: API in Visual Basic 6 working fine!

Posted: Sat Nov 05, 2011 5:06 pm
by lucubrb
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.

Re: API in Visual Basic 6 working fine!

Posted: Thu Apr 12, 2012 3:16 pm
by DorisLam
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

Re: API in Visual Basic 6 working fine!

Posted: Sat Apr 21, 2012 11:33 pm
by ax045Y
is this script run correcly at v 5.12?

Re: API in Visual Basic 6 working fine!

Posted: Sun Apr 22, 2012 2:01 am
by lucho512
is this script run correcly at v 5.12?
Yes, working fine!!!

Re: API in Visual Basic 6 working fine!

Posted: Tue Apr 24, 2012 9:25 pm
by ax045Y
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

Re: API in Visual Basic 6 working fine!

Posted: Tue Apr 24, 2012 11:55 pm
by ditonet
@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,

Re: API in Visual Basic 6 working fine!

Posted: Thu Apr 26, 2012 1:21 pm
by ax045Y
@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?

Re: API in Visual Basic 6 working fine!

Posted: Tue Oct 09, 2012 8:39 am
by bastakboys
do you have a vb.net source

Re: API in Visual Basic 6 working fine!

Posted: Thu Aug 22, 2013 12:31 pm
by amongdota
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

Re: API in Visual Basic 6 working fine!

Posted: Thu Aug 22, 2013 12:53 pm
by amongdota

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

Re: API in Visual Basic 6 working fine!

Posted: Sat Feb 22, 2014 4:05 pm
by drprotic
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

Re: API in Visual Basic 6 working fine!

Posted: Sat Feb 22, 2014 11:10 pm
by drprotic

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

Re: API in Visual Basic 6 working fine!

Posted: Tue Aug 05, 2014 8:05 pm
by edilsonlsouza
Olá,

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

Re: API in Visual Basic 6 working fine!

Posted: Tue Aug 05, 2014 8:18 pm
by edilsonlsouza
Olá,

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

Obrigado!

Re: API in Visual Basic 6 working fine!

Posted: Wed Aug 06, 2014 4:26 pm
by edilsonlsouza
Olá,

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

Re: API in Visual Basic 6 working fine!

Posted: Wed Aug 06, 2014 4:52 pm
by edilsonlsouza
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!!!

Re: API in Visual Basic 6 working fine!

Posted: Wed Aug 06, 2014 5:04 pm
by edilsonlsouza
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!

Re: API in Visual Basic 6 working fine!

Posted: Mon May 16, 2016 7:56 pm
by danieln
Hello friends. I have a question. anyone knows how to connect an api in VB a MikroTik by mac and not by ip?

Re: API in Visual Basic 6 working fine!

Posted: Tue May 17, 2016 4:10 pm
by Chupaka
API works only over TCP, it's not possible to use API over MAC connection

Re: API in Visual Basic 6 working fine!

Posted: Sat May 21, 2016 12:44 am
by danieln
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?

Re: API in Visual Basic 6 working fine!

Posted: Sat May 21, 2016 5:11 pm
by Chupaka
You cannot. RouterOS API still has 4kbytes limit on file size :)
Use ftp or scp for file transfer.

Re: API in Visual Basic 6 working fine!

Posted: Sun May 22, 2016 9:40 pm
by AboodSoft
Show how active users in datagrid

Re: API in Visual Basic 6 working fine!

Posted: Mon Mar 13, 2017 2:31 pm
by BaselMhmd
How is the load profile in the list

Re: API in Visual Basic 6 working fine!

Posted: Tue Nov 14, 2017 10:58 pm
by paramex
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 ..

Re: API in Visual Basic 6 working fine!

Posted: Thu Nov 16, 2017 10:56 am
by paramex
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"

Re: API in Visual Basic 6 working fine!

Posted: Thu Jun 21, 2018 3:08 am
by welovechonburi
why command not work
i want to disable hotspot1 by vb6

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

thank you

Re: API in Visual Basic 6 working fine!

Posted: Thu Jun 21, 2018 3:58 pm
by Chupaka
Maybe, it should be "/ip/hotspot/set", not "ip/hotspot/set"?

Re: API in Visual Basic 6 working fine!

Posted: Sun May 03, 2020 10:48 am
by dap1d5
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.

Re: API in Visual Basic 6 working fine!

Posted: Sun May 03, 2020 11:06 am
by dap1d5
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.

Re: API in Visual Basic 6 working fine!

Posted: Sun May 02, 2021 12:20 pm
by Proasg
how organize in a datagrid or any where

Re: API in Visual Basic 6 working fine!

Posted: Sun Feb 12, 2023 3:00 am
by agungsantoso
I missing winsock, are you have the link it?