Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP address of the server

Status
Not open for further replies.

cyno

Programmer
Oct 1, 2003
90
US
Is there any way to get the IP address of the server. I just need only the ip address. It doesnt matter if its a windows or sql server command. Any help would be appreciated.

Cyno
 
If you know the server's 'computer name'....

Click Start -> run
Type CMD
Click OK

Type
ping ComputerName

The message you get back will include the servers IP Address.


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Or log on to the server and run [tt]ipconfig[/tt] from the command prompt.

--James
 
Thanks for the quick response. I know the ipconfig and ping commands. But i just need to get the servername. If i run ping command this is what it gives

Reply from 145.12.25.106: bytes=32 time<10ms TTL=128

I dont need the above output format.
I am looking for just the ip address nothing else 145.12.25.106

Cyno
 
How about wrapping this in a stored procedure or function ...
Code:
DECLARE @IPAddress	VarChar(16)

SET NOCOUNT ON

CREATE TABLE #Temp 
(	TID		TinyInt	IDENTITY(1,1),
	TempText	VarChar(500) )

INSERT INTO #Temp
	EXEC Master..xp_CmdShell 'ping [b]ServerName[/b]'

SELECT @IPAddress = REPLACE(REPLACE(TempText,'Ping Statistics for ',''),':','')
FROM	#Temp
WHERE	TempText LIKE 'Ping Statistics for %'

PRINT @IPAddress

DROP TABLE #Temp

Of course you need to change the "ServerName" in the INSERT statement to reflect your servername.

Thanks

J. Kusch
 
Jay, that's a nifty bit of code. I have one suggestion for you though.

Change:
EXEC Master..xp_CmdShell 'ping ServerName'

To:
EXEC Master..xp_CmdShell 'ping ServerName -n 1'

This way, it pings only once instead of the default 4 times. The 'answer' comes back VERY quickly instead of delaying for a couple seconds.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top