sql tsql__get_server_and_client_ip_info.sql

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql tsql__get_server_and_client_ip_info.sql相关的知识,希望对你有一定的参考价值。

/*
	GET SQL IP CONNECTION INFORMATION

		FOR
			SERVER
			SPECIFIC CLIENT CONNECTIONS
*/

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


   SELECT @@SERVERNAME;



-- http://stackoverflow.com/questions/9941074/how-to-get-the-client-ip-address-from-sql-server-2008-itself

 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



-----------------

select CONNECTIONPROPERTY('client_net_address') AS client_net_address


-----------------


 SELECT CONVERT(char(15), CONNECTIONPROPERTY('client_net_address'))


 -----------------


 SELECT  hostname,
        net_library,
        net_address,
        client_net_address
FROM    sys.sysprocesses AS S
INNER JOIN    sys.dm_exec_connections AS decc ON S.spid = decc.session_id
WHERE   spid = @@SPID



------------------------

-- http://sqlmag.com/site-files/sqlmag.com/files/archive/sqlmag.com/content/content/48303/listing_01.txt
-- Listing 1: The getSQL_IPaddr.sql Procedure

create Procedure sp_get_ip_address (@ip varchar(40) out)
as
begin
Declare @ipLine varchar(200)
Declare @pos int
set nocount on
  set @ip = NULL
  Create table #temp (ipLine varchar(200))
  Insert #temp exec master..xp_cmdshell 'ipconfig'
  select @ipLine = ipLine
  from #temp
  where upper (ipLine) like '%IP ADDRESS%'
  if (isnull (@ipLine,'***') != '***')
  begin
    set @pos = CharIndex (':',@ipLine,1);
    set @ip = rtrim(ltrim(substring (@ipLine ,
    @pos + 1 ,
    len (@ipLine) - @pos)))
  end
drop table #temp
set nocount off
end

以上是关于sql tsql__get_server_and_client_ip_info.sql的主要内容,如果未能解决你的问题,请参考以下文章

sql tsql__get_schema.sql

sql tsql__template_create_database.sql

sql tsql__SQLCMD_mode_check.sql

sql tsql__get_lock_history.sql

sql tsql__kill_idle_session.sql

sql tsql__kill_db_connections.sql