redirect host ip

Hi ..
I have a script that was working with version 3, but with version 4 does not work

:local hosts [:toarray: "ABDU808"]
:local host;
:local ipnum;
:local unum;
:local usr;
:local i;

:foreach host in=$hosts do={
   :foreach i in= [/ip dhcp-server lease find host-name=$host] do={
      :set ipnum [/ip dhcp-server lease get $i address];
      :set unum [/ip hotspot active find address=$ipnum];
      :set usr [/ip hotspot active get $unum user];
      :log warning ($host . " " . $ipnum . " " . $usr);
      /ip hotspot active remove $unum
      /ip dhcp-server lease remove [/ip dhcp-server lease find host-name=$host]
   }
}

Secondly
i dont want remove user from hotspot active and dhcp-lease.
I want to modify the script to add iP of host in the proxy to redirect to a page like
/ip proxy access
add action=deny disabled=no redirect-to=“any.html” scr-address = $ip host
thanks

I suspect this line:

:local hosts [:toarray: "ABDU808"]

Should be

:local hosts [:toarray "ABDU808"];

I removed the extra colon after :toarray (generates an error in V3.30) and added a semicolon at the end.

it is working now tanks,

I modified the script to

:local hosts [:toarray "ABDU808-PC"];
:local host;
:local ipnum;
:local unum;
:local usr;
:local i;

:foreach host in=$hosts do={
   :foreach i in= [/ip dhcp-server lease find host-name=$host] do={
      :set ipnum [/ip dhcp-server lease get $i address];
      :set unum [/ip hotspot active find address=$ipnum];
      :set usr [/ip hotspot active get $unum user];
      :log warning ($host . " " . $ipnum . " " . $usr);
      /ip proxy access add action=deny disabled=no redirect-to="1any.html" scr-address =$ipnum

   }
}

it does not add ip to ip proxy and redirect it … what is rong

Are you certain the ip address you are getting from the dhcp server lease is logged in?
Change ipnum and user to global variables. Run the script and then:
/system script environment print
Is there an entry for user?

how can i do chang ipnum and user to global variables?

Change “:local ipnum” and “:local usr” to “:global ipnum” and “:global usr”…

thanks fewi..

it doesnt work where is wrong that is my script

:local hosts [:toarray "ABDU808-PC"];
:local host;
:global ipnum;
:local unum;
:global usr;
:local i;

:foreach host in=$hosts do={
   :foreach i in= [/ip dhcp-server lease find host-name=$host] do={
      :set ipnum [/ip dhcp-server lease get $i address];
      :set unum [/ip hotspot active find address=$ipnum];
      :set usr [/ip hotspot active get $unum user];
      :log warning ($host . " " . $ipnum . " " . $usr);
      /ip proxy access add action=deny disabled=no redirect-to="1any.html" scr-address =$ipnum

   }
}



[admin@serverlk] > system script environment print 
 # USER                      NAME                     VALUE                    
 0 admin                     ddnsuser                @@@                  
 1 admin                     ddnspass                      ###          
 2 admin                     ddnshost                       ###    
 3 admin                     ddnsinterface            pppoe-out1               
 4 admin                     ddnssystem               mt-4.10                  
 5 admin                     ddnsip                           ###
 6 admin                     ddnslastip               $$

This line doesn’t parse because of the space in front of the ‘=’ sign, and because it’s src-address and not scr-address:

      /ip proxy access add action=deny disabled=no redirect-to="1any.html" scr-address =$ipnum

Change it to:

      /ip proxy access add action=deny disabled=no redirect-to="1any.html" src-address=$ipnum

Thanks it works now. How can I stop recurrence of IP to add to the proxy

Try replacing

/ip proxy access add action=deny disabled=no redirect-to="1any.html" src-address=$ipnum

with

:if ([:len [/ip proxy access find src-address=$ipnum]]) do={
  :log "IP already redirected in proxy";
} else={
  /ip proxy access add action=deny disabled=no redirect-to="1any.html" src-address=$ipnum;
}

did not work

:if ([:len [/ip proxy access find src-address=$ipnum]] > 0) do={
  :log debug "IP already redirected in proxy";
} else={
  /ip proxy access add action=deny disabled=no redirect-to="1any.html" src-address=$ipnum;
}

it would be very helpful if you gave feedback more detailed than “did not work”. What didn’t work? Where does it bomb out? That saves other people from doing ALL the work for you.

hhhhh ; iam so sorry fewi for bad post but this is translations google :blush:

and thanks it is working now , :smiley: