程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 根據進程號獲取該進程所在客戶端的ip地址

根據進程號獲取該進程所在客戶端的ip地址

編輯:關於SqlServer

create PROCEDURE dbo.SP_SPIDtoIP @SPID int
AS
-- SPID to Mac
-- lj
DECLARE @Mac as varchar(12)
SELECT @Mac = NET_ADDRESS FROM master..sysprocesses WHERE SPID = @SPID
-- Mac to IP
DECLARE @MacDisplay as varchar(18)
DECLARE @IP as varchar(15)
CREATE TABLE #temp (OUTPUT varchar(255) null)
SET NOCOUNT ON
INSERT INTO #temp EXEC master..xp_cmdshell 'arp -a'
if @@error<>0
begin
RAISERROR ('The level for job_id:%d should be between %d and %d.', 16, 1)
--ROLLBACK TRANSACTION
end
SELECT @MACDisplay = LEFT(@MAC, 2) + '-' + SUBSTRING(@MAC, 3, 2) + '-' + SUBSTRING(@MAC, 5, 2) + '-' + SUBSTRING(@MAC, 7, 2) + '-' + SUBSTRING(@MAC, 9, 2) + '-' + SUBSTRING(@MAC, 11, 2) SELECT @IP = SUBSTRING(output, 3, 15) FROM #temp WHERE output LIKE '%' + @MacDisplay + '%'
-- Resolve the IP
--DECLARE @CMD as varchar(100)
--select @CMD = 'master..xp_cmdshell "ping -a ' + @IP + '"'
--exec (@CMD)
DROP TABLE #temp
SET NOCOUNT OFF
GO

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved