Chinaunix首页 | 论坛 | 博客
  • 博客访问: 592029
  • 博文数量: 40
  • 博客积分: 7274
  • 博客等级: 少将
  • 技术积分: 410
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-20 15:00
个人简介

Expired

文章分类
文章存档

2011年(1)

2008年(3)

2007年(17)

2006年(10)

2005年(9)

分类:

2007-06-24 13:08:40

有时候会接到“打后马上就挂”的匿名电话,有时候没注意,手机上面经常出现几个“未接电话”,这时就想知道到底从哪个地方打来的,心里有个底。

一般都是通过ip138.com查询的,查的次数多了,难免感觉太麻烦了,于是想到用Perl自己写一个程序来查询,当然原理还是远程调用ip138.com的HTTP请求。

脚本如下(querymb.pl)

#!/usr/bin/perl

use strict;
use Encode qw/encode decode/;
use LWP::UserAgent;

my ($mobile,$url,$ua,$resp,$line);

$mobile = $ARGV[0];
die "\nUsage: querymb.pl \n\n" if (! $mobile);

#### HTTP 请求地址
$url  = "";
$ua   = LWP::UserAgent->new();

### 超时时间
$ua->timeout(10);

### 通过 POST 方法发送请求
$resp = $ua->post($url, { "mobile" => $mobile, "action" => "mobile" });

if (! $resp->is_success) {
    die "ERR: " . $resp->status_line . "\n";
}

my ($geo,$type,$found_geo,$found_type);
foreach (split(/\r/,$resp->content)) {

    #### 由于语言环境是UTF-8,而返回的数据是 GB2312 编码,故需要转换下编码
    #### 如果您的语言环境是 GB2312,请注释下面这行
    $line = encode("utf-8",decode("euc-cn",$_));

    #### 找到归属地关键字
    if ($line =~ /卡号归属地/) {
        $found_geo = 1; next;
    }

    #### 找到卡类型关键字
    elsif ($line =~ /卡.*类.*型/) {
        $found_type = 1; next;
    }

    ### 获取归属地信息
    if ($found_geo) {
        $geo = $line;
        Encode::_utf8_off($geo);
        $geo =~ s/^\s+(.*)<\/TD>/$1/g;
        $found_geo = 0;
        $geo =~ s/ //g;
        next;
    }

    #### 获取卡信息
    if ($found_type) {
        $type = $line;
        Encode::_utf8_off($type);
        $type =~ s/^\s+(.*)<\/TD>/$1/g;
        $type =~ s/ //g;
        last;
    }
}
print "手机号码: $mobile\n";
print "卡号归属地: $geo\n";
print "卡类型: $type\n";

查询例子(偶以前的手机号码,呵呵~~~~):

# querymb.pl 13476051709
手机号码: 13476051709
卡号归属地: 湖北武汉
卡类型: 移动全球通卡
阅读(4901) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~