Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.get_process_list = function(callback) {
var query = 'path Win32_Process where "UserModeTime != 0" get Caption,ParentProcessId,ProcessId,UserModeTime';
wmic.run(query, function(err, out, wmic_pid) {
if (err) return callback(err);
callback(null, out.split(/\n/)
.filter(function(line) {
// TODO: probably locale fubar on System Idle Process
return line.length > 1 && line.indexOf("System Idle Process") === -1;
})
.splice(1)
.map(function(line) {
var fields = line.split(/\s+/),
pid = parseInt(fields[2]);
if (pid === wmic_pid) return null;
return {
}
function set_gateway(obj) {
exports.gateway_ip_for(obj.name, function(err, res) {
obj.gateway_ip = res && res != '' ? res : null;
done();
})
}
function set_netmask(obj) {
exports.netmask_for(obj.name, function(err, res) {
obj.netmask = res && res != '' ? res : null;
})
}
wmic.get_list('nic', function(err, nics) {
if (err) return callback(err);
count = nics.length;
if (count == 0){
return cb(new Error('No interfaces found.'))
}
nics.forEach(function(nic) {
if (nic.Name && nic.NetConnectionID != '' && nic.MACAddress != '') {
var obj = {
name: nic.NetConnectionID,
// description: nic.Name,
mac_address: nic.MACAddress,
ip_address: nic.IPAddress,
vendor: nic.Manufacturer,
model: nic.Description,
type: nic.Name.match(/wi-?fi|wireless/i) ? 'Wireless' : 'Wired'
return new Promise(function (resolve, reject) {
/* 所有的网络连接,包括有线网络连接,无线网络连接,虚拟网络连接等 */
Object.keys(ifaces).forEach(function (dev) {
ifaces[dev].forEach(function (details) {
if (details.family === 'IPv4') {
nets.push(details);
ips.push(details.address);
}
});
});
/* 设备管理器 */
wmic.get_list('nic', function (err, nics) {
if (err) return reject(err);
nics.forEach(function (nic) {
/* 筛选网卡 */
if (nic.Name && nic.NetConnectionID != '' && nic.MACAddress != '') {
/* 筛选无线网卡 */
if (nic.Name.match(/wi-?fi|wireless/i)) {
nets.forEach((net) => {
if (net.mac.toLowerCase() === nic.MACAddress.toLowerCase()) {
wirelessIps.push(net.address);
}
})
}
}
})
resolve({ ips, wirelessIps });
})
exports.mac_address_for(nic_name, function(err, mac){
if (err || !mac)
return cb(err || new Error('No MAC Address found.'));
wmic.get_value('nicconfig', what, 'MACAddress = \'' + mac + '\'', function(err, out){
if (err) return cb(err);
cb(null, out.split(',')[0].replace(/[^0-9\.]/g, ''));
});
})
}
exports.find_logged_user = function(callback) {
wmic.get_value('computersystem', 'username', null, function(err, stdout) {
if (err || stdout.toString().trim() == '')
return callback(err || new Error('No logged user found.'));
var out = stdout.toString().split("\\"),
user = clean_string(out[out.length-1]);
if (!user || user == '' || user == 'undefined')
return callback(err || new Error('No logged user found.'));
callback(null, user);
});
};
exports.get_wireless_interfaces_list = function(callback) {
var query = 'nic where "Name like \'%Wireless%\'" get NetConnectionID';
wmic.run(query, function(err, o) {
if (err) return callback(err);
var list = o.split("\n").splice(1).map(function(n) { return n.trim(); });
callback(null, list);
});
};
exports.get_remaining_storage = function(cb) {
var cmd ="Logicaldisk where name='C:' get Size,Freespace";
wmic.run(cmd, function(err, stdout){
if (err) return cb(err);
var cols = stdout.split("\n")[1].trim().split(/\s+/);
var info = {
total_gb: cols[0],
free_gb : cols[1],
used : (cols[0]/cols[1])*100
};
cb(null, info);
});
};
var fetch = function(key, section, value){
wmic.get_value(section, value, null, function(err, res){
if (key == 'device_type'){
res = err ? 'Desktop' : 'Laptop'
data[key] = res;
}
if (!err && res)
data[key] = res;
--count || callback(null, data)
})
}