Written by

Question Bond Xu · Jul 23, 2019

how to use M language get local Computer MAC Address

hi,ererybody!

help,

how to use M language get local Computer MAC Address?

I know get local ip use : w $ZU(67,15,$j),but i don't know this.

Comments

Bond Xu  Jul 25, 2019 to Danny Wijnschenk

Thanks.But I have something wrong with my description,I want know  how to use M get Computer physical address.

0
Bond Xu  Jul 23, 2019 to Aaron Wassall

Really thank you,sir.Version 2010 don't have,version 2016 have this method.

0
Danny Wijnschenk  Jul 25, 2019 to Vitaliy Serdtsev

Hi Vitaliy,

This is the same as 'write $SYSTEM.INetInfo.EthernetAddress(0)' in recent versions.

As said we prefer to not use $zu anymore, but since availability of  the helper classes depend on what version is used, $zu might be the only possibility unless they upgrade.

0
Bond Xu  Jul 28, 2019 to Vitaliy Serdtsev

Thank you Vitaliy,but just as Danny say,it is the same as 'write $SYSTEM.INetInfo.EthernetAddress(0)',and in cache 2010 I can not use '

w $$$DEFETHADDR

'

0
Danny Wijnschenk  Jul 25, 2019 to Bond Xu

What version are you using  and on what platform (Caché/Ensemble/Iris) ?

0
Bond Xu  Jul 28, 2019 to Danny Wijnschenk

I use cache 2010.

0
Vitaliy Serdtsev  Jul 25, 2019 to Danny Wijnschenk

I know. After all the author requested the solution on pure M and not COS.

0
Vitaliy Serdtsev  Jul 29, 2019 to Bond Xu

I checked for versions 2009.1/2010.1: unfortunately, the <FONT COLOR="#0000ff">$zu</FONT><FONT COLOR="#000000">(114,0)</FONT> returns nothing, therefore, remains variant with the command line.

Example for Windows, provided that the system has a single network card:

<FONT COLOR="#0000ff">#include </FONT><FONT COLOR="#000000">%syConfig
 </FONT><FONT COLOR="#0000ff">n </FONT><FONT COLOR="#800000">result
 </FONT><FONT COLOR="#0000ff">w $zu</FONT><FONT COLOR="#000000">(144,1,</FONT><FONT COLOR="#0000ff">$$$DEFETHADDR</FONT><FONT COLOR="#000000">),!,</FONT><FONT COLOR="#008000">"------"</FONT><FONT COLOR="#000000">,!
 
 </FONT><FONT COLOR="#0000ff">d $system</FONT><FONT COLOR="#008080">.OBJ</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Net.Remote.Utility</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">RunCommandViaCPIPE</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"getmac /NH /fo table"</FONT><FONT COLOR="#000000">,,.</FONT><FONT COLOR="#800000">result</FONT><FONT COLOR="#000000">))
 </FONT><FONT COLOR="#0000ff">w $p</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">result</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">" "</FONT><FONT COLOR="#000000">,1)</FONT>
PS: for other OS command line may be different.
0
Bond Xu  Jul 29, 2019 to Vitaliy Serdtsev

Thank you again ,Vitaliy .

 d $system.OBJ.DisplayError(##class(%Net.Remote.Utility).RunCommandViaCPIPE("getmac /NH /fo table",,.result))
 w $p(result," ",1)

this method might be return the server physical address.If I use this method on my  pc (PC as server),it return ture physical address.

0
Vitaliy Serdtsev  Jul 30, 2019 to Bond Xu

By default, the mac address of the computer on which the DBMS instance is running is returned. But you can get the mac address of any other computer, see getmac /?.

0
Bond Xu  Jul 31, 2019 to Vitaliy Serdtsev

0
Aaron Wassall · Jul 23, 2019

Hello,

This isn't the question you asked, but since you mentioned $ZU functions, please bear in mind that:

  • $ZU functions are deprecated
  • $ZU functions are no longer documented
  • Users are encouraged to replace $ZU functions with methods and properties in InterSystems class libraries that perform the equivalent actions

Your specific example, $ZU(67,15,$j), is replaced by ##class(%SYSTEM.Process).ClientIPAddress($j).

Best,

Aaron

0
Vitaliy Serdtsev · Jul 25, 2019

Try this:

<FONT COLOR="#0000ff">w $zu</FONT><FONT COLOR="#000000">(114,0)</FONT>

or

<FONT COLOR="#0000ff">w $$$DEFETHADDR </FONT><FONT COLOR="#008000">; from %syConfig.inc</FONT>

0