Storing IP addresses in Microsoft SQL Server

后端 未结 1 1255
北海茫月
北海茫月 2020-12-20 19:03

I know there\'s already a lot of questions on this topic but I might have a few extra questions.

I want to store IP addresses in a database (single column if possibl

相关标签:
1条回答
  • 2020-12-20 19:16

    I may store it in binary. An IPv6 address is 128bit -> 16 bytes long. If you store IPv4 address, you should store it at the last 4 bytes. When you use this field in application there are many built in options to convert from IPv6 to text and text back to IPv6 binary.

    In IPv4 case: this address type has its first 80 bits (10 bytes) set to zero and the next 16 bits (2 bytes) set to one (0xFF), while its last 32 bits (4 bytes) are filled with the IPv4 address. The stack implementation usually differs, so you should make the conversions at client side (from IPv6 to IPv4). This address space is safe, so it is reserved for IPv4 addressing.

    More info and more info.

    0 讨论(0)
提交回复
热议问题