惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Privacy International News Feed
F
Full Disclosure
P
Proofpoint News Feed
The Hacker News
The Hacker News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
The Blog of Author Tim Ferriss
T
Threatpost
L
Lohrmann on Cybersecurity
I
Intezer
S
SegmentFault 最新的问题
小众软件
小众软件
T
Threat Research - Cisco Blogs
MongoDB | Blog
MongoDB | Blog
美团技术团队
NISL@THU
NISL@THU
罗磊的独立博客
N
News | PayPal Newsroom
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 聂微东
W
WeLiveSecurity
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志
Scott Helme
Scott Helme
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
A
Arctic Wolf
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
I
InfoQ
Microsoft Azure Blog
Microsoft Azure Blog
S
Securelist
D
Darknet – Hacking Tools, Hacker News & Cyber Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Schneier on Security
Schneier on Security
Know Your Adversary
Know Your Adversary
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
U
Unit 42
The Cloudflare Blog
T
Tenable Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Recent Announcements
Recent Announcements
D
DataBreaches.Net
量子位

博客园 - sun@live

两段代码 <收藏>提高Web性能的14条法则(详细版) MOSS与业务系统的集成 之 单点登录 MOSS与业务系统的集成 之 自定义Membership实现Forms方式验证 .Net数据源自定义参数 JavaScript和CSS速查手册 序列化一个字符串到CDATA元素(.NET 1.1) Sandcastle工具SandcastleBuilder 清除字符串数组中,重复元素 - sun@live - 博客园 Windows Live Writer 写的一个双向选择器(JS) 论坛中,用户权限解决方法 (原创)一个改自java的代码统计工具 Web2.0用户注册,激活,密码找回模块 [学习日志]EyasBlog控件部分已基本完成-2005-12-03 学习日志(blog日历控件)-2005年11月12日 学习日志(Blog架构)-2005年11月09日 学习日志-2005年11月09日 学习计划-2005年11月07日
手机归属地数据—采集
sun@live · 2008-07-03 · via 博客园 - sun@live

在网上找了几天,能免费下载到的手机归属地数据库信息不是很全,不过网站http://www.ip138.com:8080/search.asp上查询到的数据还是比较全面,可惜拿不到他的数据库,只能想想其它办法了。

    方法一:入侵此网站,将此网站数据拿来? 
        这可是非法的行当,行不通。。。打住

    方法二:在此网站将所有号码段一个个进行查询,记下相应信息?
        算了下,联通与移动现在好像有160000个号码段,一个个手工去查,这可要命。。

    方法三:是否可写一个程序,来采集这些数据呢? 
        这方法当然可行,先分析下页面源码: 

            查询页面源码:

.
<FORM action="" method=post name="mobileform" onsubmit="return checkMobile();">
    
<TR bgColor=#eff1f3 class=tdc>
        
<TD align=middle width=130 noswap>手机号码(段) </TD>
        
<TD align=middle width=*><INPUT class=tdc name="mobile" maxLength="11">
        
<INPUT name="action" type="hidden" value=mobile>&nbsp;<INPUT class=bdtj name=B1 type=submit value="查 询">
        
</TD>
    
</TR>
</FORM>
.

结果显示页面源码: 


<TABLE width=349 border="1" align="center" cellpadding="4" bordercolor=#3366cc style="border-collapse: collapse">
    
<TR>
        
<TD colspan=2 class=tdc1 align=center height=24 >++ ip138.com查询结果 ++</TD>
    
</TR>
    
<TR class=tdc bgcolor=#EFF1F3>
        
<TD width="130" align="center" noswap>您查询的手机号码段</TD>
        
<TD width=* align="center" class=tdc2>1592031</TD>
    
</TR>
    
<TR class=tdc bgcolor=#EFF1F3>
        
<TD width="130" align="center" noswap>卡号归属地</TD>
        
<TD width=* align="center" class=tdc2>广东&nbsp;广州</TD>
    
</TR>
    
<TR class=tdc bgcolor=#EFF1F3>
        
<TD width="130" align="center" noswap>&nbsp;&nbsp;</TD>
        
<TD width=* align="center" class=tdc2>移动预付费卡</TD>
    
</TR>
    
<TR class=tdc bgcolor=#EFF1F3>
        
<TD align="center">区 号</TD>
        
<TD align="center" class=tdc2>020</TD>
    
</TR>
    
<TR class=tdc bgcolor=#EFF1F3>
        
<TD align="center">邮 编</TD>
        
<TD align="center" class=tdc2>510000 <href="http://alexa.ip138.com/post/" target="_blank">更详细的..</a></TD></TR>
</TABLE>

发现只要将手机号码段Post到http://www.ip138.com:8080/search.asp即可获取相应信息。

代码实现:

1.web request post类 

public class WebClientHelper
    
{
        
const string sUserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
        
const string sContentType = "application/x-www-form-urlencoded";
        
const string sRequestEncoding = "ascii";
        
const string sResponseEncoding = "gb2312";

        
/// <summary>
        
/// Post data到url
        
/// </summary>
        
/// <param name="data">要post的数据</param>
        
/// <param name="url">目标url</param>
        
/// <returns>服务器响应</returns>

        static string PostDataToUrl(string  postData, string url)
        
{

            
创建httpWebRequest对象

            
填充httpWebRequest的基本信息

            
填充要post的内容

            
发送post请求到服务器并读取服务器返回信息

            
读取服务器返回信息

            
return stringResponse;
        }

}

2.数据采集类 

public class AcquisitionHelper
{
        
//表格中每一个td标签内字符串
        static Regex reg = new Regex(
            
"<TD[^<]*>(?<text>[^<]*)</TD>",
            RegexOptions.IgnoreCase 
|
            RegexOptions.IgnorePatternWhitespace 
|
            RegexOptions.Multiline
            );
        
//所有超链接标签
        static Regex regA = new Regex("<a[^<]*</a>",
            RegexOptions.IgnoreCase 
|
            RegexOptions.IgnorePatternWhitespace 
|
            RegexOptions.Multiline
            );

        
public static MobileInfo Acquisition(string html)
        
{
            MobileInfo info 
= null;
            
//因<td>标签内有<a>标签,先进行替换
            html = regA.Replace(html, "");

            System.Text.RegularExpressions.MatchCollection mc 
= reg.Matches(html);

            
if (mc != null && mc.Count == 12)
            
{
                info 
= new NumInfo();
                info.Number 
= mc[3].Groups["text"].Value;
                info.Location 
= mc[5].Groups["text"].Value.Replace("&nbsp;"" ");
                info.CardType 
= mc[7].Groups["text"].Value;
                info.AreaCode 
= mc[9].Groups["text"].Value;
                info.ZipCode 
= mc[11].Groups["text"].Value;
            }


            
return info;
        }

}

3.测试一下 

static void Main(string[] args)
{
    
string postData = "mobile=1592031&action=mobile";
    
string html = WebClientHelper.PostDataToUrl(postData, "http://www.ip138.com:8080/search.asp");

    MobileInfo info 
= Acquisition(html);

    Console.WriteLine(info.Location);
    
//.
}

有了以上两个工具类,我们就很容易去遍历所有手机号码段,收集到手机号码归属信息了。

PS:记得采用多线程。。