How to get IP address

DECLARE       @Interfaces TABLE
       (
              RowID INT IDENTITY(0, 1),
              Interface CHAR(38),
              IP VARCHAR(15)
       )
 
INSERT @Interfaces
       (
              Interface
       )
EXEC   master..xp_regenumkeys     N'HKEY_LOCAL_MACHINE',
                           N'System\CurrentControlSet\Services\TcpIP\Parameters\Interfaces'
 
DECLARE       @RowID INT,
       @IP VARCHAR(15),
       @Key NVARCHAR(200)
 
SELECT @RowID = MAX(RowID)
FROM   @Interfaces
 
WHILE @RowID >= 0
       BEGIN
              SELECT @Key = N'System\CurrentControlSet\Services\TcpIP\Parameters\Interfaces\' + Interface
              FROM   @Interfaces
              WHERE RowID = @RowID
 
              EXEC   master..xp_regread   N'HKEY_LOCAL_MACHINE',
                                         @Key,
                                         N'DhcpIPAddress',
                                         @IP OUTPUT
 
              IF @IP <> '0.0.0.0'
                     UPDATE @Interfaces
                     SET    IP = @IP
                     WHERE RowID = @RowID
 
              SET    @RowID = @RowID - 1
       END
                                 
SELECT IP
FROM   @Interfaces
WHERE IP IS NOT NULL

posted @ Wednesday, July 16, 2008 1:18 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 8 and 5 and type the answer here:
 

Live Comment Preview: