Solved

Get ip address of Delphi client calling a stored procedure

Posted on 2009-05-07
8
668 Views
Last Modified: 2012-05-06
I have a Delphi program which uses Sql Server 2008.  When it calls a stored procedure, I would like to get the ip address of the Delphi client (computer hosting the Delphi program) that called the stored procedure.  Instead of the client himself sending the ip-address as a parameter.  This is for security reasons.
Is this possible?

This doesn't help, it only gives the ip-address of the machine hosting the sql server.
select * from sys.dm_exec_connections
0
Comment
Question by:FridaA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 24328343
0
 

Author Comment

by:FridaA
ID: 24334322
Thanks for the answer.

I can use
declare @host as varchar(20)
SET @host = (select host_name())
select @host

to get the host name, as suggested in your link, but I don't understand how to use the xp_cmdshell 'netstat -an'  command to get the ip-address.  Can I do this in SQL ?  pls provide sql code if you can
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24350519
Here's an example using netstat -n
For more info on how to use netstat, just run this on the Windows Command Line (CMD): netstat /?
 


 
declare @temptable table (
row varchar(2000)
)
 
declare @getipaddress table (
proto varchar(3),
localaddress varchar(20),
Foreignaddress varchar(20),
state varchar(20)
)
 
insert @temptable 
exec sp_executeSql N'xp_cmdshell  ''netstat -n'''  
 
insert @getipaddress 
select	left(ltrim(row),3) as proto,
		substring(ltrim(row), 8, 19) as localaddress,
		substring(ltrim(row), 31, 19) as Foreignaddress,
		right(row, charindex(' ', reverse(row))-1) as State
from @temptable
where left(ltrim(row),3) = 'TCP'
 
select * from @getipaddress

Open in new window

0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:FridaA
ID: 24503314
Sorry for the later answer, I'm still waiting for an answer from the dba.  The problem is that I get an error executing:  
exec sp_executeSql N'xp_cmdshell  ''netstat -n'''

The error is:
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.

And I'm waiting for the dba to answer if he can do anything, or if this is just not possible (for security reasons).

Not sure what to do in the meantime, I can't really accept a solution when I don't know if it works.  Do I just answer later when I find out?
0
 
LVL 41

Accepted Solution

by:
ralmada earned 125 total points
ID: 24503687
To use my approach, you will definitively need to activate xp_cmdshell in the Surface Area Configuration or by executing this in SSMS:
 
EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE
0
 

Author Comment

by:FridaA
ID: 24503729
Thank you for this, I will send this to the DBA.  Now he has no excuse, everything done for him :)
0
 

Author Comment

by:FridaA
ID: 24683416
Thanks for the (possible) solution.
I'll accept your solution ralmada since I'm sure it works, but the DBA at my company said that it is not an option to activate xp_cmdshell  :/
So I guess I'll have to find another solution, or just not do this at all.
Thanks for your help, and sorry for the late response.
0
 

Author Closing Comment

by:FridaA
ID: 31579094
See my last comment about the solution.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question