我用一个客户端访问sql server数据库,登录数据库我想用SQL语句获取本机的IP地址。
或者用TSQL获取!怎么取?用法越简单越好
谢谢大家。急用!

解决方案 »

  1.   

    exec xp_cmdshell 'ipconfig /all'
      

  2.   

    exec xp_cmdshell 'ipconfig'/* 
    Windows IP Configuration 
     
     
    Ethernet adapter 无线网络连接: 
     
            Media State . . . . . . . . . . . : Media disconnected 
     
    Ethernet adapter 本地连接: 
     
            Connection-specific DNS Suffix  . :  
            IP Address. . . . . . . . . . . . : 192.168.1.100 
            Subnet Mask . . . . . . . . . . . : 255.255.255.0 
            Default Gateway . . . . . . . . . : 192.168.1.1 
    NULL
    */
    本机设置[code=SQL][/code]
      

  3.   

    查看远端数据库用户登录信息 
    sp_helpremotelogin查看数据库服务器名和实例名 
    print 'Server Name...............: ' + convert(varchar(30),@@SERVERNAME) 
    print 'Instance..................: ' + convert(varchar(30),@@SERVICENAME) --不知道你想要什么>?
      

  4.   

    declare   @computerName   varchar(20),@ip   varchar(20)  
      set   @computerName='Lydia'  
      create   table   ##(str   varchar(100))  
      exec('insert   ##   exec   master..xp_cmdshell   ''ping   '+@computerName+'''')  
      select   @ip=stuff(str,1,charindex('[',str),'')  
      from   ##    
      where   ltrim(str)   like   'Pinging%'  
      select   left(@ip,charindex(']',@ip)-1)  
      drop   table   ##   
      

  5.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetClientIP]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
    drop procedure [dbo].[GetClientIP]
    GO
    /********************************************************
    功能:获取当前客户端IP地址
    ********************************************************/
    /*调用过程:
    exec GetClientIP
    */
    Create Procedure GetClientIP
    as
    declare @ip varchar(20)
    declare @hst varchar(20)
    declare @sql varchar(100)
    declare @str varchar(100)
    set @str='PING '+Host_Name() + ' -n 1'
    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
    return (0)
    Go 
    EXEC GetClientIP
      

  6.   

    exec xp_cmdshell 'ipconfig /all'
      

  7.   

    exec GetClientIP  很好, 就用这个