Is it possible to get the mac address using a stored procedure?

前端 未结 6 742
一整个雨季
一整个雨季 2020-12-12 01:07

Was wondering if it was possible to get the mac address of the server using a stored procedure? I did some searching for a while but found nothing. This is using SQL2008.

相关标签:
6条回答
  • 2020-12-12 01:23

    Well, since in Sql Server 2008, a Stored proc can contained managed code, it should be possible, however, you'd technically be running a c#/vb app which was launched by SqlServer, rather than truly getting the info from a stored proc, although that more of a theoric rather than practical difference.

    0 讨论(0)
  • 2020-12-12 01:23
    DECLARE @IP_Address varchar(20);
    DECLARE @mac_Address varchar(20);
    
    SELECT @IP_Address=client_net_address,@mac_Address=net_address 
        FROM sys.dm_exec_connections c
        join sys.sysprocesses p on c.session_id=p.spid
        WHERE c.Session_id = @@SPID
    
    0 讨论(0)
  • 2020-12-12 01:28

    I would guess that you'd need to execute a shell command from SQL to get the MAC address. If I recall correctly, you have to turn on the execute shell command option before you can use it. Then, you could run "getmac" to retrieve a list of MAC address for the interfaces on the server. You'd have to work your way through the text returned, but that shouldn't be too hard.

    0 讨论(0)
  • 2020-12-12 01:38

    declare @macadd nvarchar(50) select @macadd=net_address from master.dbo.sysprocesses where program_name like 'SQLAgent%' and hostname=SERVERPROPERTY('MachineName') and net_address<>'000000000000' --getting the MAC address set @macadd=SUBSTRING(@macadd,1,2)+'-'+SUBSTRING(@macadd,3,2)+'-'+SUBSTRING(@macadd,5,2)+'-'+SUBSTRING(@macadd,7,2)+'-'+SUBSTRING(@macadd,9,2)+'-'+SUBSTRING(@macadd,11,2) --To include '-' between each two characters of MAC address select @macadd

    0 讨论(0)
  • 2020-12-12 01:43

    A somewhat round about method!

    declare @t table
    (
    i uniqueidentifier default newsequentialid(),
    m as cast(i as char(36))
    )
    
    insert into @t default values;
    
    select
        substring(m,25,2) + '-' + 
        substring(m,27,2) + '-' + 
        substring(m,29,2) + '-' +
        substring(m,31,2) + '-' +
        substring(m,33,2) + '-' +
        substring(m,35,2) AS MacAddress
    FROM @t
    
    0 讨论(0)
  • 2020-12-12 01:43

    sys.sysprocesses, net_address column. For my connection from SSMS it's 795C70BAD9B0

    There is no equivalent in sys.dm_exec_connections (net_address is IP address not MAC address and is 111.222.111.222 from my SSMS). In fact there is no sys.sysprocesses equivalent either

    So you can just query sys.sysprocesses in your own stored proc...

    0 讨论(0)
提交回复
热议问题