-
-
Save forrest-mao/b3703b18c6054ae795d165c2513e9284 to your computer and use it in GitHub Desktop.
dns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dnsd = require('dnsd') | |
var http = require('http') | |
var datx = require('ipip-datx'); | |
var value; | |
dnsd.createServer(function(req, res) { | |
var key = JSON.stringify(req.question).split(",")[0].split(":")[1] | |
value = req.connection.remoteAddress.toString() | |
//value = req.headers['x-forwarded-for'] || | |
req.connection.remoteAddress || | |
req.socket.remoteAddress || | |
(req.connection.socket ? req.connection.socket.remoteAddress : null); | |
console.log(key.substring(1,key.length-1)) | |
console.log(value) | |
res.end('106.14.149.21') | |
}).listen(53) | |
http.createServer(function (req, res) { | |
setTimeout(function() { | |
var ip = req.connection.remoteAddress.toString().split(":")[3] | |
var city = new datx.City("mydata4vipday2.datx"); | |
// findSync 此方法只接受IPv4类型的IP地址,请自行检查参数是否符合规定; | |
//console.log(city.findSync("123.121.17.72")[1] + city.findSync("123.121.17.72")[4]); | |
res.writeHead(200, {'Content-Type': 'application/json;charset=utf-8', | |
"Access-Control-Allow-Origin": "*"}); | |
res.end(JSON.stringify( | |
{ "ClientIp": ip, | |
"ClientIsp" : city.findSync(ip)[1] + city.findSync(ip)[4], | |
"LDNS": value, | |
"LDNSIsp" : city.findSync(value)[1] + city.findSync(value)[4] | |
} | |
)); | |
}, 100); | |
}).listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment