dword2ip

This tag converts a 32-bit number back to an IPv4 address. It adjusts for a repeat factor by subtracting a multiple of 256^4 before extracting and converting each byte back to its original octet form.

Created by: hackvertor
Installed 1 times

Category: IP

Created on: Tuesday, October 22, 2024 at 11:43:38 AM

Updated on: Wednesday, November 6, 2024 at 3:20:41 PM

This is a built in tag
Tag arguments
[
   {
      "type": "number",
      "help": "This provides the repeat factor",
      "defaultValue": "1"
   }
]
Code
class dword2ip {
  encode(input, repeat) {
    const qty = 256 ** 4;
    const actualInput = input - qty * repeat;

    const segments = [];
    for (let i = 3; i >= 0; i--) {
      segments.push((actualInput >> (i * 8)) & 255);
    }

    return segments.join(".");
  }
}