Use Perl to query the home location of the mobile phone number

Source: Internet
Author: User
 
 
 
Sometimes you will receive an anonymous phone number that is "immediately hung up after the phone call". Sometimes you don't pay attention to it. There are several "missed phone calls" on your phone. Then you want to know where the phone calls are from, there is a bottom in mind.

Generally, ip138.com is used for query. If the query times are too large, it will inevitably be too troublesome. Therefore, I want to use Perl to write a program for query. Of course, the principle is to remotely call the HTTP request of ip138.com.

The script is as follows (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 <mobile number>/n" If (! $ Mobile );

#### HTTP request address
$ Url = "http://www.ip138.com: 8080/search. asp ";
$ UA = lwp: useragent-> New ();

### Timeout
$ UA-> timeout (10 );

### Send a request using the POST method
$ 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 )){

#### Because the language environment is a UTF-8, and the returned data is gb2312 encoding, it is necessary to convert the Encoding
#### If your language environment is gb2312, comment out the following line
$ Line = encode ("UTF-8", decode ("EUC-CN", $ _));

#### Locate the region keyword
If ($ line = ~ /The card number is located /){
$ Found_geo = 1; next;
}

#### Locate the card type keyword
Elsif ($ line = ~ /Card. * class. * type /){
$ Found_type = 1; next;
}

### Obtain region information
If ($ found_geo ){
$ GEO = $ line;
Encode: _ utf8_off ($ GEO );
$ GEO = ~ S/^/S + <TD. *> (. *) </TD>/$1/g;
$ Found_geo = 0;
$ GEO = ~ S/& nbsp; // G;
Next;
}

#### Obtain card information
If ($ found_type ){
$ Type = $ line;
Encode: _ utf8_off ($ type );
$ Type = ~ S/^/S + <TD. *> (. *) </TD>/$1/g;
$ Type = ~ S/& nbsp; // G;
Last;
}
}
Print "mobile phone number: $ mobile/N ";
Print "card number: $ GEO/N ";
Print "card type: $ type/N ";

Query example (even the previous mobile phone number ~~~~) :

# Querymb. pl 13476051709
Mobile phone number: 13476051709
Card No.: Wuhan, Hubei Province
Card Type: mobile global card

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.