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:

Advertisements