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.g. country, state, city, latitude/longitude, ZIPs, timezone and so on. Free database can be downloaded at http://lite.ip2location.com.
- /// <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);
- }
- }
Convert IPv6 Address to IP numbers (C#)的更多相关文章
- [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 ...
- IPv6 tutorial 4 IPv6 address syntax
https://4sysops.com/archives/ipv6-tutorial-part-4-ipv6-address-syntax/ Now that you know about the n ...
- 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: ...
- 2019牛客多校第六场 B - Shorten IPv6 Address 模拟
B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...
- 华东师大OJ:IP Address【IP地址转换】
/*===================================== IP Address Time Limit:1000MS Memory Limit:30000KB Total Subm ...
- [LintCode] Restore IP Address 复原IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- [Leetcode] restore ip address 存储IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- 468 Validate IP Address 验证IP地址
详见:https://leetcode.com/problems/validate-ip-address/description/ Java实现: class Solution { public St ...
- 牛客多校第六场 B Shorten IPv6 Address 模拟
题意: 给你一个二进制表示的IPv6地址,让你把它转换成8组4位的16进制,用冒号分组的表示法.单组的前导0可以省略,连续多组为0的可以用两个冒号替换,但是只允许替换一次.把这个地址通过这几种省略方式 ...
随机推荐
- java获取系统信息
public class SystemInfo { public static void main(String[] args) { //系统属性 Properties prop = System.g ...
- Java文件读取
package a.ab; import java.io.*; public class FileWrite { public static void main(String[] args) { Fi ...
- ubuntu 14.04 unity 管理工具 unity-tweak-tool
安装方式: sudo apt-get update sudo apt-get install unity-tweak-tool 用于更改字体,修改状态,disable 亚马逊的搜索等 功能.很好用
- Swing Note
2. Swing容器: 内容窗格.分层窗格.玻璃窗格和一个可选的菜单条.(这四个同时包含在根窗格里)(请分别向其中添加组件) ...
- SQLServer 2012之AlwaysOn —— 指定数据同步链路,消除网络抖动导致的提交延迟问题
事件起因:近期有研发反应,某数据库从08切换到12环境后,不定期出现写操作提交延迟的问题: 事件分析:在排除了系统资源争用等问题后,初步分析可能由于网络抖动导致同步模式alwayson节点经常出现会话 ...
- 【Leetcode】【Medium】Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- C++ 升级到 Vs2013后编译设置
编译 EasyDarwin 时,Vs2008的C++升级到 Vs2013时报错: 1. 找不到 windows.h 项目->属性->配置属性->C/C++->所有选项: 附加包 ...
- C#手动做一个负载均衡服务器
思路 负载均衡服务器最出名的当数 Nginx了.Nginx服务器通过异步的方式把连接转发给内网和N个服务器,用来分解单台应用服务器的压力,了解了原理及场景后,用C#来实现一个.思路如下: 1. 使用一 ...
- Java Config 下的Spring Test方式
用了三种方式: 1.纯手动取bean: package com.wang.test; import com.marsmother.commission.core.config.MapperConfig ...
- Hadoop HDFS 架构设计
HDFS 简介 Hadoop Distributed File System,简称HDFS,是一个分布式文件系统. HDFS是高容错性的,可以部署在低成本的硬件之上,HDFS提供高吞吐量地对应用程序数 ...