Mailing List Archive

nasl question : split and arrays
Hello,

I have a string that looks like this

mystring="value1=1 value2=a value3=cd value4=jj";

I would like to be able to put this in individual arrays (each of 2 elements) that can be walked through via a "foreach" iteration

My first idea was to use 2 split functions

array1=split(mystring," ");
then for each array1 member, split it again :
foreach arraymember (array1)
{
arrayentry=split(arraymember,"=");
foreach field (arrayentry)
{
display(string("item :",field,"\n");
}
}

but this does not seem to work... I get the entire string every time, so it looks like the split function is not doing anything
(however, when I do a split without parameters on a large chunck of text, trying to split this text into lines, it works fine.. but as soon as I want to use a separator, it stops working)

what is wrong here ?

thanks



____________________________________________________

Peter Van Eeckhoutte
peter.ve@telenet.be - peter.ve@corelan.be
____________________________________________________

My Blog : http://www.corelan.be:8800 (IPv4 and IPv6)
My Tools : http://freetools.corelan.be
RIPE Handle PVE50-RIPE
a.k.a. c0d3r on various forums
____________________________________________________



This transmission is intended only for use by the intended recipient(s). If you are not an intended recipient you should not read, disclose, copy, circulate or in any other way use the information contained in this transmission. The information contained in this transmission may be confidential and/or privileged. If you have received this transmission in error, please notify the sender immediately and delete this transmission including any attachments.
_______________________________________________
Plugins-writers mailing list
Plugins-writers@list.nessus.org
http://mail.nessus.org/mailman/listinfo/plugins-writers
Re: nasl question : split and arrays [ In reply to ]
On Sat, 31 Jan 2009 15:29:32 +0100
"Peter Van Eeckhoutte (corelan)" <peter.ve@corelan.be> wrote:

> array1=split(mystring," ");

The separator is a named argument: sep: " ".
And You probably want to remove it: "keep: 0"

This works:

mystring="value1=1 value2=a value3=cd value4=jj";
array1=split(mystring, sep: " ", keep: 0);
foreach arraymember (array1)
{
arrayentry=split(arraymember, sep: "=", keep: 0);
foreach field (arrayentry)
{
display("item :",field,"\n");
}
}
_______________________________________________
Plugins-writers mailing list
Plugins-writers@list.nessus.org
http://mail.nessus.org/mailman/listinfo/plugins-writers
Re: nasl question : split and arrays [ In reply to ]
Great, thanks !

I have published my plugin on my blog...
It basically is a wrapper/output parser for ike-scan,
more info can be found at

http://www.corelan.be:8800/index.php/2009/01/31/nessus-wrapper-for-ike-scan/

(it still may be a bit buggy, it most likely can be improved and extended, the code probably needs some cleaning up... but hey, this is my first script, so this is a learning process for me...)

Any comments/feedback/... is more than welcome


____________________________________________________

Peter Van Eeckhoutte
peter.ve@telenet.be - peter.ve@corelan.be
____________________________________________________

My Blog : http://www.corelan.be:8800 (IPv4 and IPv6)
My Tools : http://freetools.corelan.be
RIPE Handle PVE50-RIPE
a.k.a. c0d3r on various forums
____________________________________________________

-----Original Message-----
From: Michel Arboi [mailto:mikhail@nessus.org]
Sent: zaterdag 31 januari 2009 16:31
To: Peter Van Eeckhoutte (corelan)
Cc: Plugins-writers@list.nessus.org
Subject: Re: [Plugins-writers] nasl question : split and arrays

On Sat, 31 Jan 2009 15:29:32 +0100
"Peter Van Eeckhoutte (corelan)" <peter.ve@corelan.be> wrote:

> array1=split(mystring," ");

The separator is a named argument: sep: " ".
And You probably want to remove it: "keep: 0"

This works:

mystring="value1=1 value2=a value3=cd value4=jj";
array1=split(mystring, sep: " ", keep: 0);
foreach arraymember (array1)
{
arrayentry=split(arraymember, sep: "=", keep: 0);
foreach field (arrayentry)
{
display("item :",field,"\n");
}
}

This transmission is intended only for use by the intended recipient(s). If you are not an intended recipient you should not read, disclose, copy, circulate or in any other way use the information contained in this transmission. The information contained in this transmission may be confidential and/or privileged. If you have received this transmission in error, please notify the sender immediately and delete this transmission including any attachments.
_______________________________________________
Plugins-writers mailing list
Plugins-writers@list.nessus.org
http://mail.nessus.org/mailman/listinfo/plugins-writers