2020-07-29 06:36:35 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Hosts API
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
var SYS = require("lib/system");
|
|
|
|
var FILE = require("lib/file");
|
|
|
|
|
|
|
|
exports.getHosts = function() {
|
|
|
|
var hosts = [];
|
2020-07-30 02:53:45 +00:00
|
|
|
|
2020-07-29 06:36:35 +00:00
|
|
|
var filePath = SYS.getEnvString("windir") + "\\System32\\\drivers\\etc\\hosts";
|
2023-10-30 04:56:43 +00:00
|
|
|
var fileContent = FILE.readFile(filePath, FILE.CdoCharset.CdoUTF_8);
|
2020-07-29 06:36:35 +00:00
|
|
|
|
2020-07-29 06:48:49 +00:00
|
|
|
var rows = fileContent.split(/[\r\n]+/g).filter(function(s) {
|
|
|
|
return !(s.indexOf('#') == 0);
|
2020-07-29 06:36:35 +00:00
|
|
|
}).map(function(s) {
|
2020-07-29 06:48:49 +00:00
|
|
|
var pos = s.indexOf(" #");
|
|
|
|
return (pos > -1 ? s.substring(0, pos) : s).split(/\s+/);
|
2020-07-29 06:36:35 +00:00
|
|
|
});
|
|
|
|
|
2020-07-29 06:48:49 +00:00
|
|
|
for (var i = 0; i < rows.length; i++) {
|
2020-07-29 06:36:35 +00:00
|
|
|
hosts.push({
|
2020-07-29 06:48:49 +00:00
|
|
|
host: rows[i][0],
|
|
|
|
domain: rows[i][1]
|
2020-07-29 06:36:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return hosts;
|
|
|
|
};
|