Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Last active December 29, 2022 16:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JavaScript-Packer/b3a1479643d722e761e0 to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/b3a1479643d722e761e0 to your computer and use it in GitHub Desktop.
This simple JavaScript function set/utility provides the opportunity to obfuscate an IP address or decipher an obfuscated IP. Made by www.whak.ca
function ip2decimal(ip) {
ip = ip.split(".");
var e, w = 16777216, x = 65536, y = 256, a = eval(ip[0]), b = eval(ip[1]), c = eval(ip[2]), d = eval(ip[3]);
e = a * w + b * x + c * y + d;
return e;
}
function decimal2ip(ip) {
var w = 16777216, x = 65536, y = 256, e = eval(ip), a = e / w, z = e - (a - e % w / w) * w, b = z / x, q = z - (b - z % x / x) * x, c = q / y, d = q - (c - q % y / y) * y;
return parseInt(a) + "." + parseInt(b) + "." + parseInt(c) + "." + parseInt(d);
}
var dec = ip2decimal(prompt("Enter your IP address...", "192.168.0.100"));
prompt(decimal2ip(dec) + " will become", "http://" + dec);
//prompt(ip2decimal("192.168.0.100"), decimal2ip("3232235620"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment