ipv6怎么转换成数字(bigInteger) ipv6 to BigInteger
来源:互联网 发布:ubuntu下好用的输入法 编辑:程序博客网 时间:2024/05/01 00:05
时间:2016年08月11日1:57:58 星期四 Ken
1.为什么要转换呢?
因为需要保存在数据库中,方便查询
2.怎么转换
记得引用这两个dll
using System.Numerics;
using System.Net;
以下是 C#code
IPAddress ip = IPAddress.Parse("2400:A480:aaaa:400:a1:b2:c3:d4");
List<Byte> ipFormat = ip.GetAddressBytes().ToList();
ipFormat.Reverse();
ipFormat.Add(0);
BigInteger ipAsInt = new BigInteger(ipFormat.ToArray());
Console.WriteLine(ipAsInt);
Console.ReadLine();
输出结果:47855544357454760072796191850190012628
另外附上 pv6在线转换为int的网址 http://www.ipaddressguide.com/ipv6-to-decimal
Ps:感谢版主xuzuning
参考网址:http://stackoverflow.com/questions/17030926/ipaddress-hosttonetworkorder-with-ipv6
-----------------------------------------
顺便附上ipv4转换为数字的方法
long ip = getip("192.168.169.10");
public static long getip(string strip)
{
string[] items = strip.Split('.');
return long.Parse(items[0]) * 16777216 +
long.Parse(items[1]) * 65536 +
long.Parse(items[2]) * 256 +
long.Parse(items[3]);
}
0 0
- ipv6怎么转换成数字(bigInteger) ipv6 to BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- java biginteger怎么用
- Biginteger数字类型转换
- IPV6
- IPv6
- IPV6
- IPv6
- ERROR : arm-linux-ld:u-boot.lds:1: ignoring invalid character `#' in expression
- java创建线程
- POJ 3311 Hie with the Pie(状压DP)
- Android-->获取所有联系人以及所有的字段(联系人头像,邮箱,地址,公司等)
- Java7并发编程--3.2、CountDownLatch等待多个并发事件完成
- ipv6怎么转换成数字(bigInteger) ipv6 to BigInteger
- React-Native 学习系列课程笔记(React-Native开发环境搭建)
- Java7并发编程--3.3、CyclicBarrier在集合点同步
- 深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接
- WEB-INF 有关的目录路径问题总结
- 使用Python调整字幕文件的时间轨
- Java的泛型之简单讲解
- AFN中所使用的 '运行时' 的交换类的方法和给类动态增加方法
- linux mysql安装,启动及报错解决