Community discussions

MikroTik App
 
jmoore
just joined
Topic Author
Posts: 14
Joined: Wed Dec 07, 2005 4:42 pm

export ip addresses from particular interface

Thu Jan 22, 2009 10:41 pm

I have a scenario where I need to export all the IP's from ether2 to a file? Something similar to this put with an export command:

pr file="Ether2" where interface="ether2"

The above yields a text file with the IP's but I need it where I can import it to another router?


Joe
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7053
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: export ip addresses from particular interface

Fri Jan 23, 2009 8:51 am

I think you cant export only specific ips, but you can do workaround something like script below:
{
:local content "" 
:local ip;
/file print file=ip
:foreach i in=[/ip address find interface="ether2"] do={
      :set ip [/ip address get $i address];
      :set content ("$content\r\n/ip address add address=$ip interface=ether2);
}
/file set ip.txt contents=$content; 
}
 
mumu
just joined
Posts: 2
Joined: Fri Jan 23, 2009 12:18 pm

Re: export ip addresses from particular interface

Fri Jan 23, 2009 12:31 pm

/ip address print file=ip where interface=ether2
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7053
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: export ip addresses from particular interface

Fri Jan 23, 2009 12:54 pm

/ip address print file=ip where interface=ether2
This command will print the table of IPs on ether2, and it is not importable configuration.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: export ip addresses from particular interface

Fri Jan 23, 2009 11:46 pm

You can use on the source box:
/ip address export file=ipadd
and this on the destination box:
/ip address import file=ipadd

Getting the file from one to the other is the trick. It may require an local net tftp server, or the like, to relay the files. You could probably do the same with a text file like the suggestions above, and use the tftp server to relay that text file, and "import" with a script.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: export ip addresses from particular interface

Mon Jan 26, 2009 10:32 am

but that will get all the ip addresses that are on all interfaces - OP specifically asked for a way to get addresses of one interface.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: export ip addresses from particular interface

Mon Jan 26, 2009 11:13 am

That is why I put the reference to the previous post. It may be better to use a script to generate a text file, then move it to the new machine, and use another script to install it there.

To me, the challenge is not getting or setting the /ip address of the interface. I can do that in my sleep. It is getting it from one machine to the other. :wink:

BTW, see my post in the Beta forum. sftp would be nice, along with the RB433V.
 
breno.vale
just joined
Posts: 6
Joined: Sat Jun 14, 2008 2:12 am

Re: export ip addresses from particular interface

Wed Jan 28, 2009 4:39 pm

mrz,
i need find and export ip adress and acess list from wlan1 for exemple, I do not know how. My version is 2.9.50
I wish it were possible to explain the controls of the export.

Best Regards.

Breno Vale
Brazil
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: export ip addresses from particular interface

Wed Jan 28, 2009 9:37 pm

I am already waiting for the tftp, so I have been practicing. Here is the script for the source MT box:
EDIT: This is an array - to - CSV file converter.
:global ipadd [/ip address find interface=wlan1]
:global ipaddlist ""

:foreach i in=$ipadd do={
    :local ipstr [/ip address get $i address]

     :if ( [:len $ipaddlist] = 0) do={
          :set ipaddlist ([:toarray $ipstr])
     } else={
         :set ipaddlist ($ipaddlist + [:toarray $ipstr])
     }
}

{ /file print file=ipaddlist count-only }
{ /file set ipaddlist.txt contents=$ipaddlist }
Move the file ipaddlist.txt from the source MT box to the target MT box
Here is the code on the second MT box:
EDIT: This is a CSV file - to array converter.
:global ipadd2 ""
:global ipaddlist2 ""
:local curpos 0
:local newpos 0
:local filearray [/file find name=ipaddlist.txt]

:if ([:len $filearray] > 0) do={
   :set ipaddlist2 [/file get $filearray contents]
} else={
   :log info "file ipaddlist.txt does not exist"
}

:if ([:len $ipaddlist2] > 0) do={
    :set newpos [:find $ipaddlist2 "," $curpos]

    :while ($newpos > 0) do={
         :if ([:len $ipadd2] = 0) do={
             :set ipadd2 ([:toarray [:pick $ipaddlist2 $curpos $newpos]])
          } else={
             :set ipadd2 ($ipadd2 + [:toarray [:pick $ipaddlist2 $curpos $newpos]])
          }

        :set curpos ($newpos + 1)
        :set newpos [:find $ipaddlist2 "," $curpos]
    }

    :if ([:len $ipadd2] = 0) do={
        :set ipadd2 ([:toarray [:pick $ipaddlist2 $curpos [:len $ipaddlist2]]])
    } else={
        :set ipadd2 ($ipadd2 + [:toarray [:pick $ipaddlist2 $curpos [:len $ipaddlist2]]])
    }

    :foreach i in=$ipadd2 do={
        { /ip address add address=$i interface=wlan1 }
    }
}
Before you have this set your ip addresses, I would test this for a while to insure it does what you want. Let me know if I made any errors or typos. I tested all except assigning the ip addresses to the interface.

Keeping with standards, the ipaddlist.txt file is a CSV list.

ADD: The test was putting 3 sets of ip addresses (10.0.1.1/24, 10.0.2.1/24, and 10.0.3.1/24) on ether3, then running both routines, and
:env pri

ADD: The script no longer aborts if the CSV file does not exist. It will log it.
 
rodneal
Member Candidate
Member Candidate
Posts: 223
Joined: Mon Mar 12, 2007 7:49 pm

Re: export ip addresses from particular interface

Mon Feb 02, 2009 8:36 am

To move from system to system is as simple as dragging the file you created from the file list in one winbox interface to the file list in the other system's winbox and then run the import command.
Hope this helps.
Rod
I love drag-n-drop!!!
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: export ip addresses from particular interface

Mon Feb 02, 2009 11:23 am

Then I guess if the script interpreter could use Winbox, that would be great! :?

MikroTik has made me lazy! I used to log in to every box to see if it is up and running. What a hassle! Now a script does it at 2AM and emails me the results.

I used to log in to check the voltage on my solar powered units. Now a script keeps a record of the voltage every hour, and email me those at 11PM, unless the voltage drops below 12.5 volts, then it emails me every hour.

What part of those can Winbox do?
 
radcia
just joined
Posts: 1
Joined: Thu Oct 22, 2020 4:37 pm

Re: export ip addresses from particular interface

Thu Oct 22, 2020 4:41 pm

The export script worked as expected, but the import did not work.

Accuses syntax error:

[admin@MK02] > :if ([:len $ipaddlist2] > 0) do={
{... :set newpos [:find $ipaddlist2 "," $curpos]
syntax error (line 2 column 10)
[admin@MK02] >

:set curpos ($newpos + 1)
syntax error (line 8 column 14)
[admin@MK02] > :set newpos [:find $ipaddlist2 "," $curpos]
syntax error (line 1 column 14)

Who is online

Users browsing this forum: No registered users and 19 guests