TSQL to retrieve MAC address?

  • Does anyone know how to get the database server's MAC address inside a TransactSql script?

  • create table #mac (address varchar(255))

    insert into #mac exec xp_cmdshell 'ipconfig.exe /all'

    select substring(address, 38, 17) from #mac where address like '%Physical Address%'

    drop table #mac

  • Thanks!!  Thats a start, although I see it requires specific admin roles.

  • The MAC address is stored on the net_address column of the sysprocesses table.

    This return the MAC address of the machine running the actual process:

    use master

    select hostname, MAC=substring(net_address,1,2)+'-'+substring(net_address,3,2)+'-'+substring(net_address,5,2)+'-'+substring(net_address,7,2)+'-'+substring(net_address,9,2)+'-'+substring(net_address,11,2)

    from sysprocesses

    where spid = @@SPID

  • Very cool, but as you stated, that gets the client's mac address, not the server's.  Perhaps I could fish in that same table for processes associated with the server.

  • run sysprocesses select as a task, then own spid is running from the server.  PS multiple NICs/addresses per server is not uncommon.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply