SQL - 查询以获取服务器的 IP 地址 [英] SQL - Query to get server's IP address

查看:77
本文介绍了SQL - 查询以获取服务器的 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server 2005 中是否有查询可以用来获取服务器的 IP 或名称?

Is there a query in SQL Server 2005 I can use to get the server's IP or name?

推荐答案

SELECT  
   CONNECTIONPROPERTY('net_transport') AS net_transport,
   CONNECTIONPROPERTY('protocol_type') AS protocol_type,
   CONNECTIONPROPERTY('auth_scheme') AS auth_scheme,
   CONNECTIONPROPERTY('local_net_address') AS local_net_address,
   CONNECTIONPROPERTY('local_tcp_port') AS local_tcp_port,
   CONNECTIONPROPERTY('client_net_address') AS client_net_address 

此处的代码将为您提供 IP 地址;

The code here Will give you the IP Address;

这适用于对 SQL 2008 及更新版本的远程客户端请求.

This will work for a remote client request to SQL 2008 and newer.

如果你允许共享内存连接,那么在服务器本身上面运行会给你

If you have Shared Memory connections allowed, then running above on the server itself will give you

  • 共享内存"作为 'net_transport' 的值,以及
  • 'local_net_address' 为 NULL,以及
  • '' 将显示在 'client_net_address' 中.
  • "Shared Memory" as the value for 'net_transport', and
  • NULL for 'local_net_address', and
  • '<local machine>' will be shown in 'client_net_address'.

'client_net_address' 是发出请求的计算机的地址,而 'local_net_address' 将是 SQL 服务器(因此共享内存连接上为 NULL),以及如果某人不能使用,您将提供给某人的地址出于某种原因,服务器的 NetBios 名称或 FQDN.

'client_net_address' is the address of the computer that the request originated from, whereas 'local_net_address' would be the SQL server (thus NULL over Shared Memory connections), and the address you would give to someone if they can't use the server's NetBios name or FQDN for some reason.

我强烈建议不要使用这个答案.在生产 SQL Server 上启用外壳是一个非常糟糕的主意.

I advice strongly against using this answer. Enabling the shell out is a very bad idea on a production SQL Server.

这篇关于SQL - 查询以获取服务器的 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆