Retrieving IP address of a system with SQL Query

31 03 2008

Retrieving IP address of a system with SQL Query

CREATE PROCEDURE getIPAdress

(

@Hostname VARCHAR(255)

)

AS

SET NOCOUNT ON

CREATE TABLE #Results

(

Results VARCHAR(4000)

)

DECLARE @Commandstring VARCHAR(300)

SET @Commandstring = ‘ping ‘ + @Hostname

INSERT INTO #Results

EXEC master..xp_cmdshell @Commandstring

Select DISTINCT SUBSTRING(Results,12,CHARINDEX(’:',Results)-12) AS HostIpAdress from #Results

Where Results LIKE ‘Reply From%’

DROP TABLE #Results

GO
============================
To know result

exec getIPAdress ‘ABCXP10′

ABCXP10 is a system name

Blogged with Flock

Tags:


Actions

Information

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>