Skip to content

Instantly share code, notes, and snippets.

@GuGaobai1994
Created April 19, 2018 02:33
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save GuGaobai1994/0bfe95fe137c93333d02f9086fc44636 to your computer and use it in GitHub Desktop.
Save GuGaobai1994/0bfe95fe137c93333d02f9086fc44636 to your computer and use it in GitHub Desktop.
dns
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);
@Galvin-wjw
Copy link

good job

@geassc
Copy link

geassc commented Apr 19, 2018

fantastic!

@bernieyangmh
Copy link

great

@eliaszhang
Copy link

Amazing!

@liangchaoboy
Copy link

good!

@hktry
Copy link

hktry commented Apr 19, 2018

beautiful

@liwx
Copy link

liwx commented Oct 14, 2019

graceful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment