matlab中的ispc,在MATLAB中获取(一致的)计算机名称

可以使用的计算机的网卡的硬件地址,如建议here,用下面的Matlab代码提取它:

not_win=true;

switch computer('arch')

case {'maci','maci64'}

[~,mac_add]=system('ifconfig |grep ether | grep -o -E "([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}"');

case {'glnx86','glnxa64'}

[~,mac_add]=system('ifconfig | grep HWaddr | grep -o -E "([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}"');

case {'win32','win64'}

not_win=false;

sid = '';

ni = java.net.NetworkInterface.getNetworkInterfaces;

while ni.hasMoreElements

addr = ni.nextElement.getHardwareAddress;

if ~isempty(addr)

sid = [sid, '.', sprintf('%.2X', typecast(addr, 'uint8'))];

end

end

otherwise, error('Unknown architecture')

end

if(not_win)

mac_add=regexprep(mac_add,'\r\n|\n|\r','.');

sid=upper(strrep(mac_add(1:end-1),':',''));

end

的sid变量包含你正在寻找的唯一标识符。 您必须检测机器的体系结构,因为java.net.NetworkInterface.getNetworkInterfaces在Unix上无法正常工作,只返回正在运行的接口;因此您必须收集解析ifconfig结果的mac地址(有关示例,请参阅here)。

注意!在Mac上,如果启动虚拟机,则可以添加虚拟网络接口,因此sid可能会更改。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值