Skip to content

Instantly share code, notes, and snippets.

@squio
Created March 25, 2022 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squio/083b1e5c329d726adc3edfdd188e5510 to your computer and use it in GitHub Desktop.
Save squio/083b1e5c329d726adc3edfdd188e5510 to your computer and use it in GitHub Desktop.
Translate an IPv4 address into an integer
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