Convert IPv6 Address to IP numbers (C#)

简介: 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.

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
  1. /// <summary>
  2. /// Convert IPV6 Address to IP Number
  3. /// Free geolocation database can be downloaded at:
  4. /// http://lite.ip2location.com/
  5. /// </summary>
  6.  
  7. string strIP = "2404:6800:4001:805::1006";
  8. System.Net.IPAddress address;
  9. System.Numerics.BigInteger ipnum;
  10.  
  11. if (System.Net.IPAddress.TryParse(strIP, out address)) {
  12. byte[] addrBytes = address.GetAddressBytes();
  13.  
  14. if (System.BitConverter.IsLittleEndian) {
  15. System.Collections.Generic.List<byte> byteList = new System.Collections.Generic.List<byte>(addrBytes);
  16. byteList. Reverse();
  17. addrBytes = byteList.ToArray();
  18. }
  19.  
  20. if (addrBytes.Length > 8) {
  21. //IPv6
  22. ipnum = System.BitConverter.ToUInt64(addrBytes, 8);
  23. ipnum <<= 64;
  24. ipnum += System.BitConverter.ToUInt64(addrBytes, 0);
  25. } else {
  26. //IPv4
  27. ipnum = System.BitConverter.ToUInt32(addrBytes, 0);
  28. }
  29. }

 

目录
相关文章
|
3月前
|
数据采集 API 开发工具
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用ForceIP强制修改网口IP功能(C#)
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用ForceIP强制修改网口IP功能(C#)
48 0
|
3月前
|
JavaScript 前端开发 C#
C# webbrowser控件设置代理IP访问网站
C# webbrowser控件设置代理IP访问网站
265 5
|
小程序 前端开发 安全
【C#】 MVC4 开发小程序-实现人脸识别-本地和手机预览使用IP测试
小程序Camera组件拍照上传图片到指定的服务器(本地或者外网的IP服务器),然后C# MVC后台调用百度人脸识别接口,实现人脸识别功能呢
263 0
|
网络协议 C# 移动开发
c#获取和设置网卡ip/dns等信息
  using System; using System.Windows.Forms; using System.Management; using System.
1514 0
|
C# 负载均衡 域名解析
c#中HttpWebRequest使用Proxy实现指定IP的域名请求
我有这么一个需求: 一个域名,xxx.com,它后面其实有很多个iP:比如: 1.2.3.4,5.6.7.8,9.10.11.12这些ip上面都有同样的网站,域名解析的时候会随机分配一个ip给你(这个就是DNS负载均衡)。
3536 0
|
C#
C# 设置IP地址及设置自动获取IP
原文:C# 设置IP地址及设置自动获取IP 1.添加引用"system.Management" 2.添加using System.Management using System; using System.
2628 0
|
C#
C#获取本机IP搜集整理7种方法
① 1 private void GetIP() 2 { 3 string hostName = Dns.GetHostName();//本机名 4 //System.
813 0
|
C#
C# .net通过域名获取IP(转)
        IPAddress[] IPs = Dns.GetHostAddresses("www.by84.com");        foreach (IPAddress ip in IPs)        {           Response.
1222 0
|
3月前
|
开发框架 前端开发 .NET
C#编程与Web开发
【4月更文挑战第21天】本文探讨了C#在Web开发中的应用,包括使用ASP.NET框架、MVC模式、Web API和Entity Framework。C#作为.NET框架的主要语言,结合这些工具,能创建动态、高效的Web应用。实际案例涉及企业级应用、电子商务和社交媒体平台。尽管面临竞争和挑战,但C#在Web开发领域的前景将持续拓展。
150 3