#!/usr/bin/newlisp # newLISP IP Address calculator by ax0n # ax0n (at) h-i-r.net (define (iptostr ip4) # Converts an integer to an IP in dotted decimal notation (string (mod (/ ip4 0x1000000) 0x100) "." (mod (/ ip4 0x10000) 0x100) "." (mod (/ ip4 0x100) 0x100) "." (mod ip4 0x100)) ) (define (iptonum ip4str) # Converts an IP string to an integer (map set '(one two three four) (parse ip4str ".")) (+ (* 0x1000000 (float one)) (* 0x10000 (float two)) (* 0x100 (float three)) (float four)) ) (cond( (< (length (main-args)) 3) # Display usage if no args passed (println "usage: ipcalc.lsp ip-address/maskbits") (println "ex: ipcalc.lsp 192.168.1.20/24") ) (true (set 'ipstr (last(main-args))) (map set '(ipaddr bits) (parse ipstr "/")) (set 'binip (iptonum ipaddr)) (set 'netmask (& 0xffffffff ( << 0xffffffff (- 32 (int bits))))) (set 'netaddr (& binip netmask)) (set 'bcast (& 0xffffffff (| binip (~ netmask)))) (println "host IP: " ipaddr ) (println "netmask: " (iptostr netmask) ) (println "network: " (iptostr netaddr) ) (println "broadcast: " (iptostr bcast)) (println "Host range: " (iptostr (+ netaddr 1))" - "(iptostr (- bcast 1))) ) ) (exit)