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的可以用两个冒号替换,但是只允许替换一次.把这个地址通过这几种省略方式 ...
随机推荐
- 关于okhttp
本文出处:http://www.tuicool.com/articles/rArq63u 为什么需要一个HTTP库 Android系统提供了两种HTTP通信类,HttpURLConnection和Ht ...
- 斯坦福第十六课:推荐系统(Recommender Systems)
16.1 问题形式化 16.2 基于内容的推荐系统 16.3 协同过滤 16.4 协同过滤算法 16.5 矢量化:低秩矩阵分解 16.6 推行工作上的细节:均值归一化 16.1 问题形式 ...
- eclipse里面构建maven项目详解(转载)
本文来源于:http://my.oschina.net/u/1540325/blog/548530 eclipse里面构建maven项目详解 1 环境安装及分配 Maven是基于项目对象模 ...
- [2011山东ACM省赛] Sequence (动态规划)
Sequence Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Given an integer number sequence ...
- How to do logging in C# with log4net
If you are writing server code in C# or to a lesser extent desktop/client then it's a good idea to i ...
- EDMA3随笔
最近查DM814x上两个M3莫名其妙挂掉的问题查了将近两周,最后发现居然是各个模块的dma乱用引起的. A8上的音频mcasp用了两个dma通道…… TI给的simcop里面imx实现的swosd又用 ...
- python通过ip获取地址
# -*- coding: utf-8 -*- url = "http://ip.taobao.com/service/getIpInfo.php?ip=" #查找IP地址 def ...
- linux-4 虚拟机安装VMwareTOOls工具包
第一步:在虚拟机中选择“安装.重新安装VMwareTools(T)” 第2步: 安装VMwareTools包 1.用root登录 2. 创建 /media/cdrom [root@localhos ...
- 将枚举定义生成SQL中的Case-When-then语句
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- C#设计模式(9)——装饰者模式(Decorator Pattern)
一.引言 在软件开发中,我们经常想要对一类对象添加不同的功能,例如要给手机添加贴膜,手机挂件,手机外壳等,如果此时利用继承来实现的话,就需要定义无数的类,如StickerPhone(贴膜是手机类).A ...