I know this is a old thread that died long ago, but seeing as how I was looking for this very thing and couldn't find a solution. This is relevant so I'm bringing it back from the dead.
I wrote a PHP script to do import a list of IP addresses and related information from CSV into a Winbox .wbx file. Here is the code, feel free to update it or do with it as you wish. I hope someone finds it to be as useful as I do. I'm not a professional programmer so if you see something in my code that is wrong or could be improved, please let me and everyone else know so that we can fix it.
<?php
// ==== GENERAL INFORMATION ====
// Version 1.0
//
// Christopher Tyler
// Network Engineer
// Total Highspeed Internet Solutions
// wisptech@gmail.com
//
// Winbox import wants a pretty specific format for their wbx files. I'm not a professional
// programmer so I don't know what all the hex codes do, but they are mostly static for the
// most part. The pirmay exception is that each hex variable needs to start with the length
// of the variable that follows. Other than that they are all the same throughout the file.
//
// There aren't any *nix or Windows specific lines of code so this script should work on
// any PHP capable platform but it has only been tested on Linux at this time.
//
// ==== CSV FORMAT ====
// The CSV that is expected currently needs to be in the format of
// group,ipaddress,username,password,secure mode, keep password, note
//
// Group, IP address, username, password and note are all obviously strings that may contain
// a varialbe lenght of alpha-numeric data. Secure mode and keep password however are binary
// arguments. 0 is off/diabled and 1 in on/enabled. So if you want to have secure mode on
// you set it to 1 and 0 if you want it off, same for keep password.
//
// Do not create a label line, the csv should contain just the data you want to import and
// nothing else. As more options are added, this will reqire some changes to the format.
// Prepare the output file and remove any existing data in it
$outfile = 'winbox_output.wbx';
file_put_contents($outfile, NULL);
// Import the winbox.csv file into an array
$csv = array_map('str_getcsv', file('winbox.csv'));
// File header only needs to be inserted into the file once.
$bindata = pack('C*',0x0F,0x10,0xC0,0xBE);
// Start looping through the array to create the address list
$x = 0;
foreach($csv as $host) {
// Assign vales from the CSV file to variables as we go through them
$group = $host[0];
$ipaddr = $host[1];
$username = $host[2];
$password = $host[3];
$securemode = $host[4];
$keeppass = $host[5];
$note = $host[6];
// Spit some text out for the user so they can see what is being done for them
print 'Imported: '.$group.' : '.$ipaddr.' : '.$username.' : '.$password.' : '.$securemode.' : '.$keeppass.' : '.$note."\r\n";
$x++; // Increment $x by one
// The group tag requires a '00 00' on subsequent calls, the first instance does
// not have a leading '00 00', this section addresses that irregularity.
if ($x > 1){
$bindata .= pack('C*',0x00,0x00);
}
// For each heading, we have to determin the lenght of the string variable that we
// want to write to the file and then convert that string into hex and store it in
// a varible that will get written to the output file.
// Group
$length = (strlen($group) + 6);
$bindata .= pack('C*',$length,0x00,0x05);
$bindata .= "group";
$bindata .= $group;
// Host
$ipaddr = trim($ipaddr, "\r\n");
$length = (strlen($ipaddr) + 5);
$bindata .= pack('C*',$length,0x00,0x04);
$bindata .= "host";
$bindata .= $ipaddr;
// Keep password (1/0 to indicate on/off)
$bindata .= pack('C*',0x0A,0x00,0x08);
$bindata .= "keep-pwd";
if ($keeppass == 1){
$keeppass = pack('C*',0x01);
} else {
$keeppass = pack('C*',0x00);
}
$bindata .= $keeppass;
// Login
$length = (strlen($username) + 6);
$bindata .= pack('C*',$length,0x00,0x05);
$bindata .= "login";
$bindata .= $username;
// Note
$length = (strlen($note) + 5);
$bindata .= pack('C*',$length,0x00,0x04);
$bindata .= "note";
$bindata .= $note;
// Password
$length = (strlen($password) + 4);
$bindata .= pack('C*',$length,0x00,0x03);
$bindata .= "pwd";
$bindata .= $password;
// Secure mode (1/0 to indicate on/off)
$bindata .= pack('C*',0x0D,0x00,0x0B);
$bindata .= "secure-mode";
if ($securemode == 1){
$securemode = pack('C*',0x01);
} else {
$securemode = pack('C*',0x00);
}
$bindata .= $securemode;
// Type (Note sure what this one is for)
$bindata .= pack('C*',0x09,0x00,0x04);
$bindata .= "type";
$bindata .= "addr";
}
//End of file only needs placed once as well
$bindata .= pack('C*',0x00,0x00);
// Output the resulting data
file_put_contents($outfile, $bindata);
?>