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. }

Convert IPv6 Address to IP numbers (C#)的更多相关文章

  1. [LeetCode] Validate IP Address 验证IP地址

    In this problem, your job to write a function to check whether a input string is a valid IPv4 addres ...

  2. IPv6 tutorial 4 IPv6 address syntax

    https://4sysops.com/archives/ipv6-tutorial-part-4-ipv6-address-syntax/ Now that you know about the n ...

  3. How to support both ipv4 and ipv6 address for JAVA code.

    IPv6 have colon character, for example FF:00::EEIf concatenate URL String, IPv6 URL will like: http: ...

  4. 2019牛客多校第六场 B - Shorten IPv6 Address 模拟

    B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...

  5. 华东师大OJ:IP Address【IP地址转换】

    /*===================================== IP Address Time Limit:1000MS Memory Limit:30000KB Total Subm ...

  6. [LintCode] Restore IP Address 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  7. [Leetcode] restore ip address 存储IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  8. 468 Validate IP Address 验证IP地址

    详见:https://leetcode.com/problems/validate-ip-address/description/ Java实现: class Solution { public St ...

  9. 牛客多校第六场 B Shorten IPv6 Address 模拟

    题意: 给你一个二进制表示的IPv6地址,让你把它转换成8组4位的16进制,用冒号分组的表示法.单组的前导0可以省略,连续多组为0的可以用两个冒号替换,但是只允许替换一次.把这个地址通过这几种省略方式 ...

随机推荐

  1. java获取系统信息

    public class SystemInfo { public static void main(String[] args) { //系统属性 Properties prop = System.g ...

  2. Java文件读取

    package a.ab; import java.io.*; public class FileWrite { public static void main(String[] args) { Fi ...

  3. ubuntu 14.04 unity 管理工具 unity-tweak-tool

    安装方式: sudo apt-get update sudo apt-get install unity-tweak-tool 用于更改字体,修改状态,disable 亚马逊的搜索等 功能.很好用

  4. Swing Note

                                      2. Swing容器:   内容窗格.分层窗格.玻璃窗格和一个可选的菜单条.(这四个同时包含在根窗格里)(请分别向其中添加组件)   ...

  5. SQLServer 2012之AlwaysOn —— 指定数据同步链路,消除网络抖动导致的提交延迟问题

    事件起因:近期有研发反应,某数据库从08切换到12环境后,不定期出现写操作提交延迟的问题: 事件分析:在排除了系统资源争用等问题后,初步分析可能由于网络抖动导致同步模式alwayson节点经常出现会话 ...

  6. 【Leetcode】【Medium】Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  7. C++ 升级到 Vs2013后编译设置

    编译 EasyDarwin 时,Vs2008的C++升级到 Vs2013时报错: 1. 找不到 windows.h 项目->属性->配置属性->C/C++->所有选项: 附加包 ...

  8. C#手动做一个负载均衡服务器

    思路 负载均衡服务器最出名的当数 Nginx了.Nginx服务器通过异步的方式把连接转发给内网和N个服务器,用来分解单台应用服务器的压力,了解了原理及场景后,用C#来实现一个.思路如下: 1. 使用一 ...

  9. Java Config 下的Spring Test方式

    用了三种方式: 1.纯手动取bean: package com.wang.test; import com.marsmother.commission.core.config.MapperConfig ...

  10. Hadoop HDFS 架构设计

    HDFS 简介 Hadoop Distributed File System,简称HDFS,是一个分布式文件系统. HDFS是高容错性的,可以部署在低成本的硬件之上,HDFS提供高吞吐量地对应用程序数 ...