1/** 2 obtain IP information ISP 3/4 ipinfo = function (IP, callback) 5 {6 this. HTTP = require ('http'); 7} 8 9 ipinfo. prototype. log = function (STR) 10 {11 console. log (STR); 12} 13 14 ipinfo. prototype. geturl = function (IP) 15 {16 var url = '/iplookup. PHP? Format = JSON & IP = '+ IP; 17 return URL; 18} 19 20 ipinfo. prototype. gethost = function () 21 {22 var host = 'int .dpool.sina.com.cn '; 23 return host; 24} 25 26 ipinfo. prototype. getinfo = function (IP, callback) 27 {28 var Options = {29 HOST: This. gethost (), 30 Port: NULL, 31 path: This. geturl (IP) 32} 33 34 var curtthis = This; 35 var Req = This. HTTP. get (options, function (RES) {36 res. setencoding ('utf8'); 37 var DATA = ""; 38 res. on ('data', function (chunk) {39 data + = chunk; 40}); 41 42 res. on ("end", function () {43 callback (data); 44 // curtthis. log (data); 45}); 46}); 47 48 req. on ('error', function (e) {49 callback (null, e); 50 // curtthis. log ("error"); 51}); 52 53 req. end (); 54} 55 56 57 // example58/* 59 var test = new ipinfo (); 60 61 var info = ["221.8.120.56", "221.8.120.56 ", "123.172.68.122"]; 62 63 for (VAR I = 0; I <3; I ++) 64 {65 test. getinfo (info [I], function (data, err) {66 If (ERR) {console. log (ERR)} 67 else68 console. log (data); 69}); 70} 71 */
IP address queried by Sina Interface