客户端IP地址的最大长度 [英] Max length for client ip address

查看:166
本文介绍了客户端IP地址的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

IPv6地址文本表示的最大长度?

您建议使用存储客户端IP地址的数据库列的最大大小?我现在设置为16,但是我可以获得比IPv6更长的IP地址吗?

What would you recommend as the maximum size for a database column storing client ip addresses? I have it set to 16 right now, but could I get an ip address that is longer than that with IPv6, etc?

推荐答案

对于IPv4,您可以避开存储IP地址的4个原始字节(IP地址中的周期之间的每个数字为0-255,即一个字节)。

For IPv4, you could get away with storing the 4 raw bytes of the IP address (each of the numbers between the periods in an IP address are 0-255, i.e., one byte). But then you would have to translate going in and out of the DB and that's messy.

IPv6地址是128位(而不是32位的IPv4地址)。它们通常写成由冒号分隔的8个4位十六进制数字组: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 。 39个字符适用于以此格式存储IPv6地址。

IPv6 addresses are 128 bits (as opposed to 32 bits of IPv4 addresses). They are usually written as 8 groups of 4 hex digits separated by colons: 2001:0db8:85a3:0000:0000:8a2e:0370:7334. 39 characters is appropriate to store IPv6 addresses in this format.

编辑:但是,有一个警告,有关IPv4映射IPv6地址的详细信息,请参阅@ Deepak的答复。 (正确的最大IPv6字符串长度为 45个字符。)

However, there is a caveat, see @Deepak's answer for details about IPv4-mapped IPv6 addresses. (The correct maximum IPv6 string length is 45 characters.)

这篇关于客户端IP地址的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆