zoukankan      html  css  js  c++  java
  • node获取windows pc 机器的标示

    var exec = require('child_process').exec;
    
    if(process.platform != "win32"){
    	//window
    	throw new Error("only support windows");
    	return ;
    }
    
    //获取网卡号
    function netNumber(){
    	return new Promise(function(resolve,reject){
    		 exec('ipconfig/all', function (error, stdout, stderr) {
    	        if(error){
    				reject(error);	            
    	            return;
    	        }
    	        var mex = "Realtek PCIe GBE Family Controller";
    	        var index= stdout.indexOf(mex);
    	        var str = stdout.substring(index);
    	       	var res = str.split("
    ")[1].split(":")[1].trim();
       			resolve(res);
    		});
    	})
    }
    
    //wmic diskdrive get serialnumber  获取硬盘序列号
    function diskNumber(){
    	return new Promise(function(resolve,reject){
    		exec('wmic diskdrive get serialnumber', function (error, stdout, stderr) {
            if(error){
              	reject(error);
                return;
            }
       			resolve(stdout.split("
    ")[1].trim())
    		});
    	});
    }
    
    module.exports = function(){
    	return Promise.all([netNumber(),diskNumber()]).then(function(res){
    			var str = res[0];
    			for(var i = 0; i < res[1].length; i++){
    				if(i % 2 == 0 ){
    					str = str + "-"
    				}
    				str = str + res[1][i];
    			}
    			return Promise.resolve(str);
    	})
    }
    

      

    var guid = require("./guid");
    
    guid().then(function(res){
    	console.log(res);
    }).catch(function(res){
    	console.log(res);
    })
    

     

     

  • 相关阅读:
    mysql 位操作支持
    统计代码行数
    git merge的参数--squash的用处
    bash和zsh切换
    nginx 添加https支持
    查看Memcache运行状况
    unkown host mac 解决
    react-redux中的重要API解析
    js 同步延时调用
    从输入 URL 到浏览器渲染完成
  • 原文地址:https://www.cnblogs.com/muamaker/p/10043793.html
Copyright © 2011-2022 走看看