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 |