我正在尝试将IPv6转换为ASN。我已经能够获得两个64位的部分,但我不知道如何将它组合在一起以获得单个ASN作为字符串,以便我可以在数据库中查找它。
到目前为止的代码:
byte[] addrBytes = System.Net.IPAddress.Parse(ipv6Address).GetAddressBytes();
if (System.BitConverter.IsLittleEndian)
{
//little-endian machines store multi-byte integers with the
//least significant byte first. this is a problem, as integer
//values are sent over the network in big-endian mode. reversing
//the order of the bytes is a quick way to get the BitConverter
//methods to convert the byte arrays in big-endian mode.
System.Collections.Generic.List<byte> byteList = new System.Collections.Generic.List<byte>(addrBytes);
byteList.Reverse();
addrBytes = byteList.ToArray();
}
ulong addrWords1, addrWords2;
if (addrBytes.Length > 8)
{
addrWords1 = System.BitConverter.ToUInt64(addrBytes, 8);
addrWords2 = System.BitConverter.ToUInt64(addrBytes, 0);
}
else
{
addrWords1 = 0;
addrWords2 = System.BitConverter.ToUInt32(addrBytes, 0);
}
请帮助将addrWords1和addrWords2放在一起代表ASN的字符串?
E.g。 2001:200 ::应该返回ASN 42540528726795050063891204319802818560