用SQL语句得到本机的IP或者是计算机名怎么写啊?高手指点,如果是两个连接怎么办,就是一个宽带,一个VPN连接的

解决方案 »

  1.   

    大版主的:declare @ip varchar(15),@sql varchar(1000)--得到ip地址
    create table #ip(a varchar(200))
    set @sql='ping '+host_name()+' -a -n 1 -l 1'
    insert into #ip exec master..xp_cmdshell @sqlselect @ip=left(a,patindex('%:%',a)-1) from(
    select a=substring(a,patindex('Ping statistics for %:%',a)+20,20)
    from #ip where a like 'Ping statistics for %:%') a--显示结果
    select 用户计算机名=host_name(),ip地址=@ipdrop table #ip
      

  2.   

    服务器名称:
    select serverproperty('ServerName');
      

  3.   

    机器名:
    select serverproperty('MachineName');
      

  4.   

    exec master..xp_cmdshell 'nbtstat -an'
      

  5.   

    declare @ip varchar(15)--得到ip地址
    create table #ip(a varchar(200))
    insert into #ip exec master..xp_cmdshell 'nbtstat -an'select @ip=left(a,patindex('%]%',a)-1) from(
    select a=substring(a,patindex('%:%',a)+3,20)
    from #ip where a like '%Node IpAddress%') a--显示结果
    select 用户计算机名=host_name(),ip地址=@ipdrop table #ip
      

  6.   

    select @@servername
    select 用户计算机名=host_name()
    和这个结果不相同?