I don't have a website I maintain right now so I thought I'd post this
to the mailing list.

I have a need to scan a list of IP addresses and I wanted the scan
order to be random.  Nmap can do this.  However, I also want the scan
order to be consistent so I can do handy things like diff output logs
for changes.  The following program generates a list of IPs,
randomizes their order, and outputs to a file.

The program ends up being very small but expressive; I developed
against Clojure 1.1.  Because this was one of my first clojure
programs, it took a long time to write and I'd like the thank everyone
that answered my questions in IRC and the mailing list.

For completeness' sake, you can use the list of IPs with e.g. the
following nmap command:
nmap -iL ips.txt -sP -oG scanned_results.txt

http://gist.github.com/484747

- - - -

; Generate a list of random IPs to be fed into nmap so that nmap may scan
; aggressively but not swamp any given subnet within the 172.16.0.0/12 range.
;
; Licensed under the EPL (fwiw  ;)

(use '[clojure.contrib.seq-utils :only (shuffle)]
     '[clojure.contrib.duck-streams :only (write-lines)])

(write-lines
  "./ips.txt"
  (shuffle
    (for [octet1 [172]
          octet2 (range 16 33)
          octet3 (range 256)
          octet4 (range 256)]
      (str octet1 \. octet2 \. octet3 \. octet4))))

- - - -

- Ryan (arkh)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to