如何将 IP 地址映射到八个字符长的字符串?
我有一个服务器 IP 地址列表,我的应用程序与这些地址进行交互以收集实时数据。收集到的数据被发送到另一个系统中的插槽。这些槽由八个字符长度的字符串标识。我想以编程方式创建这个插槽。我想创建一个将服务器的 IP 地址映射到八个字符的字符串的方法。例如。给定 192.80.24.200 它将返回 SLOT0001 我认为哈希函数将是一个很好的解决方案,但我不确定它是如何实现的。
该应用程序是 C# Winforms .Net Framework 4.0。服务器是基于Windows的服务器。
I've a list of server ip addresses that my application interacts to in order to collect live data. And the collected data is sent to slots in another system. These slots are identified by eight character length strings. And I would like to create this slots programmatically. I would like to create a method that will map an ip address of a server to an eight character string. eg. given 192.80.24.200 it will return SLOT0001 I assume a hash function will be a good solution but I'm not sure how it's implemented.
The application is a C# Winforms .Net Framework 4.0. And the servers are windows based servers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,将 IP 地址转换为 32 位数字,然后将其转换为 8 个十六进制数字。
Well, convert the IP address into a 32-bit number, and convert that to 8 hexadecimal digits.
IP地址长度为4个字节,可以直接写成8个十六进制字符:
An IP address is 4 bytes long, which can be directly written as eight hexadecimal characters:
八个字符是十六进制表示。
这是将 IP 打包为八个字节的更快、更简单的方法
Eight characters is a HEX representation.
this is faster and simple way to pack IP into eight bytes