Last active
December 25, 2019 15:40
-
-
Save licson/06fe41160b5dc5e14cde2c40b749886b to your computer and use it in GitHub Desktop.
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
| const exec = require('child_process').exec; | |
| const request = require('request'); | |
| function loadRouteList() { | |
| return new Promise(function (resolve, reject) { | |
| request("http://f.ip.cn/rt/isproutes-ct.txt", function (e, res, body) { | |
| if (e) { | |
| reject(e); | |
| return; | |
| } | |
| resolve(body.split('\n').filter((x) => x.indexOf('#') < 0)); | |
| }); | |
| }); | |
| } | |
| function execMtrAndMatch(ip) { | |
| return new Promise(function (resolve, reject) { | |
| exec(`mtr --report-wide --report-cycles=2 --timeout=0.3 ${ip}`, function (e, stdout) { | |
| if (e) { | |
| reject(e); | |
| return; | |
| } | |
| if (stdout.split('\n').length < 10) { | |
| resolve(null); | |
| return; | |
| } | |
| resolve(stdout.indexOf('pccwbtn.net') > -1); | |
| }); | |
| }); | |
| } | |
| loadRouteList().then(function (routes) { | |
| let i = 0; | |
| let iter = function () { | |
| if (i == routes.length) return; | |
| let ip = routes[i].substr(0, routes[i].length - 3); | |
| execMtrAndMatch(ip).then(function (res) { | |
| if (res !== null) { | |
| process.stdout.write(routes[i] + '\t\t...\t'); | |
| process.stdout.write((res === true ? 'Yes' : 'No') + '\n'); | |
| } | |
| i++; | |
| iter(); | |
| }); | |
| }; | |
| iter(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment