Convert IPv6 Address to IP numbers (C#)
2016-10-27 11:41 狼人:-) 阅读(668) 评论(0) 编辑 收藏 举报URL: http://lite.ip2location.com/
Use the code below to convert the IP address of your web visitors and lookup for their geographical location, e.g. country, state, city, latitude/longitude, ZIPs, timezone and so on. Free database can be downloaded at http://lite.ip2location.com.
Expand | Embed | Plain Text
-
/// <summary>
-
/// Convert IPV6 Address to IP Number
-
/// Free geolocation database can be downloaded at:
-
/// http://lite.ip2location.com/
-
/// </summary>
-
-
string strIP = "2404:6800:4001:805::1006";
-
System.Net.IPAddress address;
-
System.Numerics.BigInteger ipnum;
-
-
if (System.Net.IPAddress.TryParse(strIP, out address)) {
-
byte[] addrBytes = address.GetAddressBytes();
-
-
if (System.BitConverter.IsLittleEndian) {
-
System.Collections.Generic.List<byte> byteList = new System.Collections.Generic.List<byte>(addrBytes);
-
byteList.Reverse();
-
addrBytes = byteList.ToArray();
-
}
-
-
if (addrBytes.Length > 8) {
-
//IPv6
-
ipnum = System.BitConverter.ToUInt64(addrBytes, 8);
-
ipnum <<= 64;
-
ipnum += System.BitConverter.ToUInt64(addrBytes, 0);
-
} else {
-
//IPv4
-
ipnum = System.BitConverter.ToUInt32(addrBytes, 0);
-
}
-
}
声明:此博有部分内容为转载,版权归原作者所有~
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
2011-10-27 “Asp.Net微型服务器”根据博友们的要求改版了,也出.NET4.0版本了,要更新的博友们赶快下吧