Wesley Porter
Wesley Porter

Reputation: 1461

Get external IP address of a website

I have seen many methods for easily retrieving the internal IP address of a machine or website. However, I can't seem to find a good way to retrieve the external IP address.

To clarify, if I provide a URL like bitbucket.org, I want to get the external IP address of bitbucket. Is there a web service out there that can easily do this?

EDIT: Suppose, for this case, that I am on the same network as bitbucket.org.

I am filling a database with information about all the websites our company manages. We want to keep track of the info and note periodic changes, with specific data. This program will be deployed on one of the local servers on the same network as the servers that the websites are running from. I believe the only good way of retrieving the external IP address for each site is to use an external web service.

Upvotes: 4

Views: 7062

Answers (5)

alex
alex

Reputation: 12654

You can use System.Net.Dns.GetHostEntry() to get IP address by the host name.

Upvotes: 7

Rup
Rup

Reputation: 34418

You could query an external public DNS server, e.g. Google's one at 8.8.8.8. From the command line

nslookup bitbucket.org 8.8.8.8

or in Linux dig bitbucket.org @8.8.8.8. There's a few C# libraries out there that will let you query a specific DNS server e.g. DnsNet built on top of this CodeProject article (found searching - I haven't tried it to recommend it). This does rely on Google continuing the service, though, but that seems safe.

Upvotes: 3

DermFrench
DermFrench

Reputation: 4057

If you are trying to get your "wan" ip instead of your local IP you could try something like this. You could also add code like this inside a webservice and add it to the PC bitbucket is on (if it is really on your network and you can have access to install webservices).

Public Shared ReadOnly Property IpAddress() As String
        Get
            If String.IsNullOrWhiteSpace(_ipAddress) Then
                Try
                    Dim webClient As New WebClient
                    Dim result As String = webClient.DownloadString("http://checkip.dyndns.org")

                    Dim fields = result.Split(" ")
                    _ipAddress = fields.Last
                    _ipAddress = _ipAddress.Replace("</body></html>", "")
                Catch ex As Exception
                    _ipAddress = "errorFindingIp"
                End Try
            End If
            Return _ipAddress
        End Get
    End Property

Upvotes: -1

Icemanind
Icemanind

Reputation: 48736

I think you can just use Dns.GetHostAddresses to get the IP Address. From the MSDN Documentation:

The GetHostAddresses method queries a DNS server for the IP addresses associated with a host name.

UPDATE:

If you are looking for a web service, try looking at whoisxmpapi.com. As you can see from this sample, they do provide the name server IP Address in their XML output. You can then use something like this to get the IP address directly from the name server!

Upvotes: 0

Dustin Hodges
Dustin Hodges

Reputation: 4193

You can use the ping utility. In windows, open up a command window by hitting the windows key + r and type

ping bitbucket.org

Upvotes: 2

Related Questions