Community discussions

MikroTik App
 
Mangofi
just joined
Topic Author
Posts: 10
Joined: Sat Aug 19, 2017 11:09 pm

Help changing clients ip address with a script. (New to scripting)

Fri Feb 24, 2023 3:23 pm

I’m very new to this and I did read some of the manual but yet not sure on how I should approach this

I have 760 pppoe users with static ip
The user network is 172.19.x.x/18
I need to change it to something else let’s say 192.19.x.x but keeping the last 2 pair of digits the same. Maybe this can be tho e with a simple script
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help changing clients ip address with a script. (New to scripting)

Fri Feb 24, 2023 4:04 pm

yes...
but where the user take the IP? on ppp/secret profile?
 
Mangofi
just joined
Topic Author
Posts: 10
Joined: Sat Aug 19, 2017 11:09 pm

Re: Help changing clients ip address with a script. (New to scripting)

Fri Feb 24, 2023 4:12 pm

They all have been set manually on the ppp/secret remote address field.
Last edited by Mangofi on Sat Feb 25, 2023 1:44 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help changing clients ip address with a script. (New to scripting)

Fri Feb 24, 2023 4:50 pm

yes...
but where the user take the IP? on ppp/secret profile?
They all have been set manually on the ppp/secret remote address field.
You want something that automatically change all ppp/secret/<user-profile>/remote-address from 172.19.x.x to 192.19.x.x ???
but why /18 is present on what you write for remote address?
you specify the /18 just because you have the 172.19.x.x/18 range and you want change only the users with 172.19.x.x?
 
Mangofi
just joined
Topic Author
Posts: 10
Joined: Sat Aug 19, 2017 11:09 pm

Re: Help changing clients ip address with a script. (New to scripting)

Fri Feb 24, 2023 7:17 pm

You want something that automatically change all ppp/secret/<user-profile>/remote-address from 172.19.x.x to 192.19.x.x ???
but why /18 is present on what you write for remote address?
you specify the /18 just because you have the 172.19.x.x/18 range and you want change only the users with 172.19.x.x?
[/quote]

Actually I think that is /16
I specified it because I have group of client with ip addresses all from 172.19.0.0 to 172.19.64.254
And I need to change all those to 192.19.x.x
Last edited by Mangofi on Sat Feb 25, 2023 1:44 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help changing clients ip address with a script. (New to scripting)

Fri Feb 24, 2023 7:43 pm

On first step backup & expor the config, check if this simulate the correct results, this do nothig, simple print what must we do.
:foreach user in=[/ppp secret find where (remote-address in 172.19.0.0/18)] do={
    :local usr [/ppp secret get $user name] 
    :set usr [:pick "$usr                               " 0 30]
    :local old [/ppp secret get $user remote-address]
    :local new (($old & 0.0.255.255) | 192.19.0.0)
    :put "$usr$old\t->\t$new"
#    /ppp secret set $user remote-address=$new
}

But 172.19.0.0/18 is go from 172.19.0.0 to 172.19.63.255, 172.19.64.0/24 is not covered...

You need also the 172.19.64.0/24 from 172.19.64.0.0 to 172.19.64.255?
Replace
(remote-address in 172.19.0.0/18)
with
((remote-address in 172.19.0.0/18) or (remote-address in 172.19.64.0/24))

Triple check the results.
All is at your own risk.
If all is working as expected, apply the changes relaunching the script removing the comment "#" in front of /ppp...
Last edited by rextended on Sat Feb 25, 2023 3:55 am, edited 1 time in total.
 
Mangofi
just joined
Topic Author
Posts: 10
Joined: Sat Aug 19, 2017 11:09 pm

Re: Help changing clients ip address with a script. (New to scripting)

Fri Feb 24, 2023 10:29 pm

1. it was from 172.19.0.0 to 172./19.63.255, my bad. so /18.
2. i created the script on the rb and run it. the run count went up by one but i dont see any output in the log.

i haven’t remove the "#" as you suggested so i can check that things are actually going well. not sure on where i should look for the output tho.
thanks for your time and help i do really appreciate it!
Last edited by Mangofi on Sat Feb 25, 2023 1:42 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help changing clients ip address with a script. (New to scripting)

Sat Feb 25, 2023 12:13 am

>>> "simple print what must we do"

I never say to run as script, open terminal, and paste it,
you see on terminal what change the script do, before you remove the # for make the change.
No log (read what the script do...), only as terminal results.

Please do not quote uselessly all the block, edit and remove on previous post the quoted part, please...
 
Mangofi
just joined
Topic Author
Posts: 10
Joined: Sat Aug 19, 2017 11:09 pm

Re: Help changing clients ip address with a script. (New to scripting)

Sat Feb 25, 2023 1:44 am

oh i did try it from the terminal but i just get this error:
bad command name get (line 2 column 17)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help changing clients ip address with a script. (New to scripting)

Sat Feb 25, 2023 3:55 am

oh i did try it from the terminal but i just get this error:
bad command name get (line 2 column 17)
Fixed the previous script for all routeros version, retry.
 
Mangofi
just joined
Topic Author
Posts: 10
Joined: Sat Aug 19, 2017 11:09 pm

Re: Help changing clients ip address with a script. (New to scripting)

Sat Feb 25, 2023 7:45 pm

awesome! its working perfectly fine. thanks!!

Who is online

Users browsing this forum: No registered users and 11 guests