Skip to content

Instantly share code, notes, and snippets.

@nexpr
Created February 13, 2017 14:16
Show Gist options
  • Select an option

  • Save nexpr/21061dd89ca76ac3857c1f26f64d59bb to your computer and use it in GitHub Desktop.

Select an option

Save nexpr/21061dd89ca76ac3857c1f26f64d59bb to your computer and use it in GitHub Desktop.
make id from ip
const ip2id = ip =>
ip.split(".")
.map(e => String.fromCharCode(e))
.map(e => btoa(e))
.map(e => e.replace(/=+$/g, ""))
.join("")
ip2id("100.200.100.200")
// "ZAyAZAyA"
ip2id("1.2.3.4")
// "AQAgAwBA"
ip2id("9.9.9.9")
// "CQCQCQCQ"
ip2id("192.168.1.5")
// "wAqAAQBQ"
ip2id("9.99.9.99")
// "CQYwCQYw"
ip2id("99.9.99.9")
// "YwCQYwCQ"
ip2id("....")
// "AAAAAAAAAA"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment