Solved

Retreive External IP Address

Posted on 2012-03-22
1
321 Views
Last Modified: 2012-03-25
Hi all,
Is there a built in function/stored procedure in sql server that returns the external ip address?
similar to http://www.whatismyip.com

If there isn't one, how do I use http://www.whatismyip.com in sql code?

Many thanks in advance

Programmers
0
Comment
Question by:Programmers
1 Comment
 
LVL 16

Accepted Solution

by:
DcpKing earned 500 total points
ID: 37752523
Try this code

set nocount on
declare @ip varchar(255), @cmd varchar(100)
set @cmd = 'ping  -n 1 ' + HOST_NAME()
create table #temptb (grabfield varchar(255))
insert into #temptb exec master.dbo.xp_cmdshell @cmd
select @ip = substring( grabfield,  
                                        charindex('[',grabfield)+1,
                                        charindex(']', grabfield)-charindex('[',grabfield)-1   )
from #temptb  
where left(grabfield,7) = 'Pinging'
print @ip
drop table #temptb
set nocount off

and if you get a really weird set of results you may well be on a virtual box with IPV6, etc.

From outside the box I get
Pinging sys76.tekstlogik.com [192.168.7.59] with 32 bytes of data:
From inside:
Pinging sys76.tekstlogik..com [fe80::c0f3:b3a:9464:39a%11] with 32 bytes of data:

(credit: several posts on http://www.sqlservercentral.com/Forums/Topic150196-8-1.aspx from 2004).
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now