本人知道ipv4怎么转换为数字
问一下ipv6是怎么转换的,如: 2400:A480:aaaa:400:a1:b2:c3:d4 == > 47855544357454760072796191850190012628
这里有个国外网站它是可以的http://www.ipaddressguide.com/ipv6-to-decimal
问一下ipv6是怎么转换的,如: 2400:A480:aaaa:400:a1:b2:c3:d4 == > 47855544357454760072796191850190012628
这里有个国外网站它是可以的http://www.ipaddressguide.com/ipv6-to-decimal
解决方案
40
BigInteger num = BigInteger.Parse("47855544357454760072796191850190012628"); Console.WriteLine(string.Join(",", num.ToByteArray()));
得:212,0,195,0,178,0,161,0,0,4,170,170,128,164,0,36
IPAddress ip = IPAddress.Parse("2400:A480:aaaa:400:a1:b2:c3:d4"); Console.WriteLine(string.Join(",", ip.GetAddressBytes().Reverse()));
得:212,0,195,0,178,0,161,0,0,4,170,170,128,164,0,36
原因是涉及大数运算,你本人看着办吧
测试了一下,这样就可以
Console.WriteLine(new BigInteger( ip.GetAddressBytes().Reverse()));