如何从SQL Server 2008中本身客户端的IP地址? [英] How to get the client IP address from SQL Server 2008 itself?
问题描述
我有插入/更新触发器/删除。这是工作的罚款。另外,我需要从那里的变化是由客户端的IP地址。我需要在T-SQL,这意味着,不以任何Web表单,但在SQL / T-SQL,而我的触发器将被解雇。
I have a trigger for insert/update/delete. That is working fine. Also, I need the client's IP address from where the changes are made. That I need in T-SQL, that means, not in any web form but in the SQL/T-SQL while my trigger will get fired.
此外,我去-ogled,找来有存储在一个名为master数据库中的程序 xp_cmdshell的
当与 IPCONFIG $ C $执行C>我们可以得到IP地址。我想,当你有数据库管理员访问权限,这只会工作。煤矿主机是一个共享的主机,所以我没有这样的特权。是否有任何其他方式?
Also I go-ogled, and got that there is stored procedure in master database named xp_cmdshell
which when executed with ipconfig
we can get the IP Address. I think this will work only when you have administrative access to database. Mine hosting is a shared hosting , so I don't have such privilege. Is there any other way out?
请帮忙
在此先感谢
请注意:我没有我的SQL Server 2008数据库的管理权限。我需要一个解决方案作为身份验证的用户。
Please note: I don't have administrative privileges on my SQL Server 2008 database. I need a solution as an authenticated user.
另一个更新:
我已经得到了解决,这将对于我的方案的工作查询
I have got the solution, the query that will work for my scenario is
SELECT hostname, net_library, net_address
FROM sys.sysprocesses
WHERE spid = @@SPID
,它执行如需要的,但只有一个问题,即net_address不在IP格式。下面是我的结果是:
It executes as needed but there is only one issue, that net_address is not in IP format. below is mine result:
hostname net_library net_address
IPC03 TCP/IP AE8F925461DE
我急切地想知道:
I am eager to know:
-
什么是net_address在这里?难道又是MAC地址或某些IP地址等?
What is net_address here? Is is MAC Address or Some IP address etc?
有没有办法转换为net_address IP?
Is there any way to convert net_address to ip?
小小的要求
接听/评论/ downvoting之前,我想请你去通过的问题,第一,彻底。我发现有些人评论/不通过的问题会正确downvoted。没有问题,每个人都会犯错。但是,并非每一次犯错。 :)
Before answering/commenting/downvoting, I would request you to go through the question, first, thoroughly. I found some guys commented/downvoted without properly going through the question. No issues, everybody makes mistakes. But not every time make mistake. :)
推荐答案
我发现了一些可能为你工作。
I found something which might work for you
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
也有一个看看这篇文章了解获取客户端的IP地址
Also have a look at this article about Get client IP address
这篇关于如何从SQL Server 2008中本身客户端的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!