Senior
Tell me about IPv4 and IPv6
sobes.tech AI
Answer from AI
IPv4 is the Internet Protocol version 4, using 32-bit addresses, which provides about 4.3 billion unique addresses. Addresses are written as four decimal numbers from 0 to 255, separated by dots, for example, 192.168.0.1.
IPv6 is the next version of the protocol with 128-bit addresses, providing virtually unlimited unique addresses. Addresses are written as eight groups of four hexadecimal digits, separated by colons, for example, 2001:0db8:85a3:0000:0000:8a2e:0370:7334.
Main differences:
- Address size: 32 bits vs. 128 bits.
- Format of recording and representation.
- IPv6 supports automatic address configuration (SLAAC), improved routing, and built-in security support (IPSec).
In Go, the net package is used for working with IP addresses, supporting both protocols:
package main
import (
"fmt"
"net"
)
func main() {
ip := net.ParseIP("192.168.1.1")
fmt.Println("IPv4:", ip)
ip6 := net.ParseIP("2001:db8::68")
fmt.Println("IPv6:", ip6)
}