有没这样的系统变量或函数可以直接获取?

解决方案 »

  1.   

    用 xp_cmdshell 執行DOS命令 
      

  2.   

     1:得到客户端的IP地址  /************* IP **************/  declare @ip varchar(20),@hst varchar(20),@sql varchar(100)  declare @str varchar(100)  set @str='PING '+Host_Name()  create table #tmp(aa varchar(200))  insert #tmp exec master..xp_cmdshell @str  select top 1 @ip = replace(left(aa,charindex(':',aa)-1),'Reply from ','')   from #tmp where aa like 'reply from %:%'  drop table #tmp  select @ip      2:得到网卡的物理地址  create table #tb(re varchar(255))  insert into #tb exec master..xp_cmdshell 'ipconfig /all'    select 网卡物理地址=substring(re,charindex(':',re)+1,255) from #tb where re like '%Physical Address. . . . . . . . . :%'     drop table #tb    3: 将IP地址段转成每三位用点号分开   create function getIP(@a varchar(15))  returns varchar(15)  As  begin  declare @s varchar(15)  set @s = ''  while charindex('.',@a) >0  begin  set @s = @s + right('000' + left(@a,charindex('.',@a)),4)  set @a = right(@a,len(@a)-charindex('.',@a))  end  set @s = @s + right('000' + @a,3)  return @s  end    /*  Select dbo.getIP('202.1.110.2')  ---------------   202.001.110.002    (所影响的行数为 1 行)  */  --drop function getIP    
      

  3.   

    请问xp_cmdshell 没有开启的话该怎么办?
      

  4.   

    SQL Server 已封鎖元件 'xp_cmdshell' 的 程序 'sys.xp_cmdshell' 之存取,因為此元件已經由此伺服器的安全性組態關閉。系統管理員可以使用 sp_configure 來啟用 'xp_cmdshell' 的使用。如需有關啟用 'xp_cmdshell' 的詳細資訊,請參閱《SQL Server 線上叢書》中的<介面區組態>(Surface Area Configuration)。
    用下面一句话就可以了解决了。 
    EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;
    关闭一样.只是将上面的后面的那个"1"改成"0"就可以了. 
    EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 0;RECONFIGURE; 
      

  5.   

    好像有个系统扩展存储过程...记不清了.
    用shell也是个办法,不过直接:
    xp_cmdshell ipconfig
    就行了.