IP Address
Supports both IPv4 address format to IPv6 and IPv6 to IPv4 conversion.

Description

A numerical address is a form of an IP address, which is the digital representation of an IP address.
Visiting http://192.168.1.123 in a browser has the same effect as visiting http://3232235899.

Differences between IPv4 and IPv6
IPv4 (Internet Protocol version 4): It is the current mainstream IP address, consisting of 32 bits. It can accommodate approximately 4.3 billion addresses. It is represented as a collection of 4 parts separated by 3 dots, each part having 8 bits of data, known as an octet.
For example: 192.168.1.123

IPv6 (Internet Protocol version 6): It is an address representation rule developed based on the IPv4 platform to overcome the limitations of IPv4. It consists of 128 bits, totaling 2^128 (approximately 3.4×10^38) = 340282366920938463463374607431768211456 addresses. The range of IPv6 addresses goes from [0000:0000:0000:0000:0000:0000:0000:0000] to [ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff].
For example: 0000:0000:0000:0000:0000:ffff:c0a8:017b


Method of converting an IPv4 address to an integer number is as follows:
For example: 192.168.1.123
The IP address is divided into 4 numbers by 3 dots, each ranging from 0 to 255, making each number 8 bits.
With a total of 32 bits or 4 bytes, it can be represented using an unsigned data type like uint.
The calculation process is as follows:
192*256^3 + 168*256^2 + 1*256^1 + 123*256^0 = 3232235899


Method of converting an Integer to IPv4 address is as follows:
For example: 3232235899
The calculation process is as follows:
  • 3232235899 & 255, extract the low byte, resulting in 123
  • (3232235899 >> 8) & 255, right shift by 8 bits, remove the original low 8 bits, then extract the low byte, resulting in 1
  • (3232235899 >> 16) & 255, right shift by 16 bits, remove the original low 16 bits, then extract the low byte, resulting in 168
  • (3232235899 >> 24) & 255, right shift by 24 bits, remove the original low 24 bits, then extract the low byte, resulting in 192

0 Comments

0 / 300