CREATE FUNCTION [dbo].[GetCurrentIP] () RETURNS varchar(255) AS BEGIN DECLARE @IP_Address varchar(255); SELECT @IP_Address = client_net_address FROM sys.dm_exec_connections WHERE Session_id = @@SPID; Return @IP_Address; END GO -- RUN SELECT dbo.GetCurrentIP ()
SELECT CONNECTIONPROPERTY('local_net_address') AS 服务端IP地址, CONNECTIONPROPERTY('local_tcp_port') AS 服务端口, CONNECTIONPROPERTY('client_net_address') AS 客户端IP地址
select @@SERVERNAME select HOST_NAME()