IP地址解析
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地址解析的更多相关文章
- HBase启动时IP地址解析不正确的问题及解决方法
HBase启动时遇到IP地址解析不正确,连不上Regionserver , 配置文件上写的 192.168.100.28, 错误信息 Problem binding to /202.102.110. ...
- Linux ->> UBuntu 14.04 LTE下主机名称和IP地址解析
UBuntu 14.04 LTE下主机名称和IP地址解析一些相关的配置文件: /etc/hosts: 主机文件.手工配置IP地址和主机名称间的映射.格式为每行一条映射条项: <machine_n ...
- C#编程_单线程IP地址解析
单线程IP地址解析 目标程序 界面如下图 设计方法:完成单个IP地址解析,循环调用方法,完成扫描. 注意用stopwatch计算时间. 实现思路 先知道怎么解析一个单个的IP地址. 用循环的方法解 ...
- <TCP/IP>地址解析协议ARP
从前两章中有学到,网络层地址和链路层地址是由不同的,一个是物理地址,一个是IP地址.物理地址固定存储在网卡中,不会改变,而IP地址是可以网络管理员和用户自己分配的 在传统的IPv4网络中,一台A主机要 ...
- 本地hosts文件IP地址解析
localhost是一个域名,127.0.0.1为IP地址.Windows系统中,约定127.0.0.1为本地IP地址.localhost是其对应的域名.配置是在hosts文件中设置的,Windows ...
- JAVA实现IP地址解析
转载至:http://blog.csdn.net/dragontang/article/details/4151660 http://www.iteye.com/topic/340548#
- TCP/IP协议(二)tcp/ip基础知识
今天凌晨时候看书,突然想到一个问题:怎样做到持续学习?然后得出这样一个结论:放弃不必要的社交,控制欲望,克服懒惰... 然后又有了新的问题:学习效率时高时低,状态不好怎么解决?这也是我最近在思考的问题 ...
- logresolve - 解析Apache日志中的IP地址为主机名
logresolve是一个解析Apache访问日志中IP地址的后处理程序. 为了使对名称服务器的影响降到最低,logresolve拥有极为自主的内部散列表缓存, 使每个IP值仅仅在第一次从日志文件中读 ...
- 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 ...
随机推荐
- error: png.h not found.
跑php设备 --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable- ...
- 添加xml文件编辑语法提示
找到Struts的lib目录 找到struts2-core-文件并解压开 这个struts.dtd文件才是我们需要添加的文件 双击XML Catalog 点击ADD Key中复制粘贴D:\web\st ...
- Ubuntu下安装KDE及安装中文环境
进入Ubuntu的默认安装的桌面后打开终端,输入 sudo apt-get install kubuntu-desktop 回车后输入密码接下来提示下载KDE需要多少空间,解压后需要多少空间,询问是否 ...
- 怎么样putty打开图形化管理工具,在终端上
有时需要在putty这种图形终端开放的图形化管理工具将出现以下错误: [root@node2 ~]# Traceback (most recent call last): File "/us ...
- Java正则表达式例子汇总
1.过滤特殊字符 package com.sheepmu.text; /* * @author sheepmu */ public class HWCompetition { public stati ...
- 基于Tkinter利用python实现颜色空间转换程序
主要基于colorsys实现,例子是从hls转换到rgb,假设要换颜色空间非常easy仅仅须要改动一个函数 用到了Scale和Canvas组件 代码例如以下: from Tkinter import ...
- Ubuntu下搭建ASP.NET 5
在Ubuntu下搭建ASP.NET 5开发环境 0x00 写在前面的废话 年底这段时间实在太忙了,各种事情都凑在这个时候,没时间去学习自己感兴趣的东西,所以博客也好就没写了.最近工作上有个小功能要 ...
- sails 相关文章
Node 框架之sails http://cnodejs.org/topic/555c3c82e684c4c8088a0ca1
- [LeetCode53]Maximum Subarray
问题: Find the contiguous subarray within an array (containing at least one number) which has the larg ...
- decimal ? 含义
例如: decimal ? je = zfje; 意思是 将 JE赋值为 ZFJE , 并且允许 JE 为 NULL 值 这时JE为引用类型