根据进程号获取该进程所在客户端的IP地址
类别: 数据库教程
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
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
- 上一篇: 关于值班管理的存储过程
- 下一篇: 在业务系统中处理小数精度, 四舍五入,全舍弃,全进位的方法
-= 资 源 教 程 =-
文 章 搜 索