Home page logo

nmap-dev logo Nmap Development mailing list archives

Re: [Patch] KRAD Ascii Art (A short and sweet patch)
From: Jay Bosamiya <jaybosamiya () gmail com>
Date: Wed, 19 Mar 2014 23:31:46 +0530

On 3/19/2014 8:40 PM, Daniel Miller wrote:
Not sure if this is what you meant, but this turns out to be better (avoids the whole sort issue and has fewer processes):

cat $(ls | awk 'BEGIN{srand();}{lines[++d]=$0}END{print lines[int(1+rand()*d)]}')

I added the docs/leet-nmap-ascii-art*.txt 2>/dev/null needed to make the code look at the necessary files. The other 2>/dev/null at the end stops it from throwing an error if no docs/leet-nmap-ascii-art*.txt file exists.
Thus the command becomes into

   cat $(ls docs/leet-nmap-ascii-art*.txt 2>/dev/null | awk
   'BEGIN{srand();}{lines[++d]=$0}END{print lines[int(1+rand()*d)]}')

This works pretty well except for the fact that it seems to generate the same image each time. Looking at the random number generator in awk, it seems to produce numbers that are very close to each other each time, so I felt that a better thing to do would be the following

   cat $(ls docs/leet-nmap-ascii-art*.txt 2>/dev/null | awk
   lines[int(rand()*49139)%d+1]}') 2>/dev/null

It seems to work quite well then. (the 49139 is a prime number not close to a power of 2)

I have put this into the patch, attached it and also revised the github gist [1].


[1] https://gist.github.com/jaybosamiya/e2cecc305b4055cb7776

Attachment: leetascii.patch.txt

Sent through the dev mailing list
Archived at http://seclists.org/nmap-dev/

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]