using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.Collections; namespace getipaddress
{
class Program
{
static void Main(string[] args)
{
WebClient wc = new WebClient();
string html = wc.DownloadString("http://iframe.ip138.com/ic.asp");//获取本机外网IP
int iBegin = html.IndexOf('[') + ;
int iEnd = html.IndexOf(']');
string strIP = html.Substring(iBegin, iEnd - iBegin); html = wc.DownloadString(string.Format("http://ip.taobao.com/service/getIpInfo.php?ip={0}",strIP));//获得IP地址对应的信息
html = ConvertUnicode2Chinese(html);
Console.WriteLine(html);
Hashtable ht = new Hashtable();
GetInfo(html,ht); }
/// <summary>
/// 将编码转换成字符
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
private static string ConvertUnicode2Chinese(string result)
{
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})", RegexOptions.IgnoreCase | RegexOptions.Singleline);
return reg.Replace(result,delegate(Match m){ return ((char)Convert.ToInt32(m.Groups[].Value, )).ToString(); });
} /// <summary>
/// 将获得的JSON数据存放在Hashtable中
/// </summary>
/// <param name="source"></param>
/// <param name="ht"></param>
private static void GetInfo(string source,Hashtable ht)
{
Regex reg = new Regex("(?<=\")\\w*(?=\")|(?<=\")(\\d{1,3}\\.){3}\\d{1,3}(?=\")|(?<=\")-\\d*(?=\")");
MatchCollection result = reg.Matches(source);
int i = ;
object Key="";
foreach (Group item in result)
{
if (i == )
{
ht.Add(item.Value, "");
Key = item.Value;
i++;
}
else
{
ht[Key] = item.Value;
i--;
}
}
Console.ReadKey();
}
} }

IP地址解析的更多相关文章

  1. HBase启动时IP地址解析不正确的问题及解决方法

    HBase启动时遇到IP地址解析不正确,连不上Regionserver , 配置文件上写的 192.168.100.28, 错误信息  Problem binding to /202.102.110. ...

  2. Linux ->> UBuntu 14.04 LTE下主机名称和IP地址解析

    UBuntu 14.04 LTE下主机名称和IP地址解析一些相关的配置文件: /etc/hosts: 主机文件.手工配置IP地址和主机名称间的映射.格式为每行一条映射条项: <machine_n ...

  3. C#编程_单线程IP地址解析

    单线程IP地址解析 目标程序 界面如下图 ​ 设计方法:完成单个IP地址解析,循环调用方法,完成扫描. 注意用stopwatch计算时间. 实现思路 先知道怎么解析一个单个的IP地址. 用循环的方法解 ...

  4. <TCP/IP>地址解析协议ARP

    从前两章中有学到,网络层地址和链路层地址是由不同的,一个是物理地址,一个是IP地址.物理地址固定存储在网卡中,不会改变,而IP地址是可以网络管理员和用户自己分配的 在传统的IPv4网络中,一台A主机要 ...

  5. 本地hosts文件IP地址解析

    localhost是一个域名,127.0.0.1为IP地址.Windows系统中,约定127.0.0.1为本地IP地址.localhost是其对应的域名.配置是在hosts文件中设置的,Windows ...

  6. JAVA实现IP地址解析

    转载至:http://blog.csdn.net/dragontang/article/details/4151660 http://www.iteye.com/topic/340548#

  7. TCP/IP协议(二)tcp/ip基础知识

    今天凌晨时候看书,突然想到一个问题:怎样做到持续学习?然后得出这样一个结论:放弃不必要的社交,控制欲望,克服懒惰... 然后又有了新的问题:学习效率时高时低,状态不好怎么解决?这也是我最近在思考的问题 ...

  8. logresolve - 解析Apache日志中的IP地址为主机名

    logresolve是一个解析Apache访问日志中IP地址的后处理程序. 为了使对名称服务器的影响降到最低,logresolve拥有极为自主的内部散列表缓存, 使每个IP值仅仅在第一次从日志文件中读 ...

  9. MySQL [Warning]: IP address 'xxxx' could not be resolved: Name or service not known

    MySQL的error log 出现大量的 DNS反解析错误. DNS解析是指,将 域名解析成ip地址: DNS反解析是指,将IP地址反解析成域名: Version: MySQL Community ...

随机推荐

  1. Test SRM Level Three: LargestCircle, Brute Force

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3005&rd=5858 思路: 如果直接用Brute F ...

  2. 【白痴弟弟和你加强应用层】阅读 Develop API Guides 思考(一个)

    转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 动态检測设备属性 关于targetSdkVersion的含义 关于onSaveInstanceState的高 ...

  3. 乐在其中设计模式(C#) - 访问者模式(Visitor Pattern)

    原文:乐在其中设计模式(C#) - 访问者模式(Visitor Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 访问者模式(Visitor Pattern) 作者:webabc ...

  4. Appium0.18.x迁移到Appium1.x须知事项(灰常实用,解答了本人几个疑问)

    英文原版:https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/migrating-to-1-0.md Migr ...

  5. 连接字符串中Min Pool Size的理解是错误,超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。

    Min Pool Size的理解是错误的 假设我们在一个ASP.NET应用程序的连接字符串中将Min Pool Size设置为30: <add name="cnblogs" ...

  6. [LeetCode283]Move Zeros将一个数组中为0的元素移至数组末尾

    题目: Given an array nums, write a function to move all 0's to the end of it while maintaining the rel ...

  7. 利用Eclipse中的Maven构建Web项目(三)

    利用Eclipse中的Maven构建Web项目 1.将Maven Project转换成动态Web项目,鼠标右键项目,输入"Project Facets" 2.依据Dynamic W ...

  8. 上Mysql com.mysql.jdbc.StatementImpl$CancelTask内存泄漏问题和解决方法

    近来在负责公司短信网关的维护及建设,随着公司业务发展对短信依赖越来越严重了,短信每天发送量也比曾经每天40多w发送量暴增到每天达到200w发送量.由于是採用Java做发送底层,压力递增情况下不可避免的 ...

  9. 开源Math.NET基础数学类库使用(13)C#实现其他随机数生成器

    原文:[原创]开源Math.NET基础数学类库使用(13)C#实现其他随机数生成器                本博客所有文章分类的总目录:http://www.cnblogs.com/asxiny ...

  10. poj2386 Lake Counting(简单DFS)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...