Community discussions

MikroTik App
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

script error for wan ip info

Fri Jan 09, 2015 11:08 am

I have Wan interface with 4 ips (means 4 ips are assigned to single interface and only one ip is active rest are disabled)
I am using followign script to print WAN ip in LOG window
:global externalInterface "ether1"
:local currentIP
:set currentIP [/ip address get [find interface="$externalInterface"] address]
:log warning "$currentIP"
But when I execute the script, I get this error in terminal
interrupted
           invalid internal item number
When I select LAN interface which have only one IP, it prints the ip ok,
I want to print wan ip which is active at a moment

I tried following script, but it prints all the IP addresses assigned to WAN interface, even the disabled ones. I want to print only active (enabled) IP address.
:global ifs [/ip address find interface="ether1"]
:local ifips ""
:foreach ifip in=$ifs do={
   :if ( $ifips = "" ) do={:set ifips "$[/ip address get $ifip address]"} else {:set ifips "$ifips \n$[/ip address get $ifip address]"}
}
:log warning ($ifips)
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: script error for wan ip info

Sat Jan 10, 2015 3:42 am

check this:

ros code

/ip address
		:foreach i in=[ find interface=wan] do={
	:local ip [get value-name=address $i]
		:local status [ get value-name=disabled $i]
			:if ($status = false) do={
	:log error "ip address $ip"
 }
 }


change the interface name..
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

Re: script error for wan ip info

Sat Jan 10, 2015 9:01 am

check this:

ros code

/ip address
		:foreach i in=[ find interface=wan] do={
	:local ip [get value-name=address $i]
		:local status [ get value-name=disabled $i]
			:if ($status = false) do={
	:log error "ip address $ip"
 }
 }
change the interface name..
Working Great Thanks man. I want to give but where the Add KARMA option have gone in this new theme of mikrotik php forum ?
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: script error for wan ip info

Sat Jan 10, 2015 11:56 am

You need to switch the theme.

Who is online

Users browsing this forum: diamuxin, dredex and 22 guests