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的可以用两个冒号替换,但是只允许替换一次.把这个地址通过这几种省略方式 ...
随机推荐
- return和exit函数的区别
在上Linux课的时候,老师提到一句,调用vfork产生的子进程就是为了使用exec族函数来执行其他的代码逻辑. 在子进程退出的时候有两种方式,exit和exec族函数,不能使用return,为什么不 ...
- Github心得体会
Github是一个代码托管的网站,以前端的代码为主,还有很多互动. 在我的理解看来,github并不仅仅是一个代码库,你可以自由注册,推送自己一些感兴趣编写的源代码.它不是单纯的保存代码,更多的是让 ...
- unity --项目总结
最近做的unity的项目涉及到的问题如下: 1.绘制折线图问题: 起初利用的unity自带的linerender组件,这种方法绘制的线不均匀,效果不好.然后又利用画线插件Ves……开头的那个,结果那个 ...
- C# 特殊处理使用方法
1.时间处理 Model.PiDaiTime.ToString("yyyyMMdd") == "00010101" ? DateTime.Now.ToStrin ...
- 【乔布斯05年斯坦福大学毕业典礼上的演讲】——Stay Hungry, Stay Foolish.(转)
Steve Jobs: Commencement Address at Stanford University "Stay Hungry, Stay Foolish." 求知若饥, ...
- sublime text 也能矩形选择
原来用editplus,但发现sublime text后便果断选择这个,她真的是很完美,但有一点就是不能像editplus一样矩形选择(Ctrl+鼠标左键这我知道,但感觉很麻烦)而感到小小的不爽... ...
- MySQL数据库小实验
实验1 1.创建数据表 CREATE TABLE guest( Accounts ) NOT NULL, Details ) NOT NULL, Date ) NOT NULL, ,), Class ...
- Happymenu新的开始
1. 2014年10月28日入职happymenu,希望能和公司一起成长.年轻的时候就得多折腾! 2. 第一个任务:安装,配置ubuntu14环境,尽快熟悉操作.目前基本工作操作已经掌握. 安装好Ub ...
- 修改注册表来修改IE的设置---资料汇总
原文链接: http://blog.csdn.net/wangqiulin123456/article/details/17068649 附带批处理执行脚本: @echo off &title ...
- 利用Junit4进行程序模块的测试,回归测试
①在你的工程里导入JUnit4的包 ②右击创建JUnit测试类,在测试类中编写测试代码即可. JUnit 目前需要掌握的有一下几点: Fixture系列:BeforeClass,AfterClass, ...