From 7556c0cce431c3496340e55a0448de05c9771069 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 29 Jul 2020 15:36:35 +0900 Subject: [PATCH] Update lib/hosts.js, lib/system.js, ssloader.js --- lib/hosts.js | 29 +++++++++++++++++++++++++++++ lib/system.js | 2 +- ssloader.js | 21 ++++++++++++++------- 3 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 lib/hosts.js diff --git a/lib/hosts.js b/lib/hosts.js new file mode 100644 index 0000000..23c8caa --- /dev/null +++ b/lib/hosts.js @@ -0,0 +1,29 @@ +//////////////////////////////////////////////////////////////////////// +// Hosts API +//////////////////////////////////////////////////////////////////////// + +var SYS = require("lib/system"); +var FILE = require("lib/file"); + +exports.getHosts = function() { + var hosts = []; + + var filePath = SYS.getEnvString("windir") + "\\System32\\\drivers\\etc\\hosts"; + var fileContent = FILE.readFile(filePath, "utf-8"); + + var lines = fileContent.split(/[\r\n]+/g).filter(function(s) { + return !(s.indexOf('#') == 0) + }).map(function(s) { + return s.replace(/\s\s/g, ' '); + }); + + for (var i = 0; i < lines.length; i++) { + var col = lines[i].split(' '); + hosts.push({ + host: col[0], + domain: col[1] + }); + } + + return hosts; +}; diff --git a/lib/system.js b/lib/system.js index 1bfb504..e9b9728 100644 --- a/lib/system.js +++ b/lib/system.js @@ -137,7 +137,7 @@ exports.getNetworkInterfaces = function() { try { rows.push({ Caption: objItem.Caption, - IPAddresses: objItem.IPAddress.toArray(), + IPAddress: objItem.IPAddress.toArray().join(','), MACAddress: objItem.MACAddress }); } catch(e) {} diff --git a/ssloader.js b/ssloader.js index 3bfbcc8..2d499cc 100644 --- a/ssloader.js +++ b/ssloader.js @@ -5,21 +5,28 @@ var SS = require("lib/shadowsocks"); var WINTAP = require("lib/wintap"); var SYS = require("lib/system"); +var HOSTS = require("lib/hosts"); exports.main = function() { console.log("Connecting to shadowsocks..."); var proxyport = SS.connect(); console.log(proxyport); - - console.log("Gethering informations of network interfaces"); + + console.log("Gethering network interfaces..."); var inets = SYS.getNetworkInterfaces(); - for(var i in inets) { - console.log(inets[i].Caption); - console.log(" > " + inets[i].IPAddresses.join(",")); - console.log(" > " + inets[i].MACAddress); + for (var i in inets) { + console.log("Caption > " + inets[i].Caption); + console.log(" > IPAddress > " + inets[i].IPAddress); + console.log(" > MACAddress > " + inets[i].MACAddress); } - console.log("Installing new WindowsTAP..."); + console.log("Gethering hosts..."); + var hosts = HOSTS.getHosts(); + for (var i = 0; i < hosts.length; i++) { + console.log(hosts[i].domain + " -> " + hosts[i].host); + } + + console.log("Gethering WindowsTAP interfaces..."); console.log(WINTAP.query("tap0901")); console.log("Done"); };