Solved

Retreive External IP Address

Posted on 2012-03-22
1
320 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

771 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

12 Experts available now in Live!

Get 1:1 Help Now