Skip to content

Instantly share code, notes, and snippets.

@ianatha
Created March 11, 2013 07:45
Show Gist options
  • Save ianatha/5132609 to your computer and use it in GitHub Desktop.
Save ianatha/5132609 to your computer and use it in GitHub Desktop.
#lang mzscheme
(require srfi/1/list
srfi/14/char-set
srfi/13/string)
(define ip-to-long
(lambda (ip-as-string)
(apply +
(map *
(map string->number (string-tokenize ip-as-string (string->char-set “0123456789″)))
(map (lambda (x) (expt 256 x)) (iota 4 3 -1))))))
(define long-to-ip
(lambda (ip-as-long)
(string-join
(map
number->string
(unfold-right
zero?
(lambda (x) (remainder x 256))
(lambda (x) (quotient x 256))
ip-as-long))
“.”)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment