Created
March 25, 2022 14:32
-
-
Save squio/083b1e5c329d726adc3edfdd188e5510 to your computer and use it in GitHub Desktop.
Translate an IPv4 address into an integer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ip='192.168.1.123'; | |
const decimal_ip = ip.split('.').reverse().map((e,i) => parseInt(e)*(2**(8*i))).reduce((sum, n) => sum + n); | |
// decimal_ip = 3232235899 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment