可以使用的计算机的网卡的硬件地址,如建议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可能会更改。