How to obtain the public IP address of a machine outside the firewall

  • Thread starter Thread starter Ed Willis
  • Start date Start date
E

Ed Willis

We have several offices that have a DSL or Cable modem where the IP address
is dynamic and changes often. I created a VB app that obtains the IP address
but it obtains the IP address within the firewall and we need the public IP
address of the machine outside the firewall so we can use Remote Desktop
connection for problem resolution etc.

Here is my current code:
Dim myWorkstation As String = System.Net.Dns.GetHostName()

Dim IPAdress As String =
System.Net.Dns.Resolve(myWorkstation).AddressList(0).ToString

Dim MachineName As String = Environment.MachineName

How can I obtain the other IP address?

Thanks.
 
Ed:

I have been able to do it with:

Request.ServerVariables.Item("REMOTE_HOST")

In web applications that I have written.

Hope that helps!

Fred
 
How can you do it in a Web Service?

Fred Nelson said:
Ed:

I have been able to do it with:

Request.ServerVariables.Item("REMOTE_HOST")

In web applications that I have written.

Hope that helps!

Fred
 
Dim objHttpRequest As HttpRequest

Dim objHttpContext As HttpContext

Dim FirewallIPAddress As String

objHttpContext = HttpContext.Current()

objHttpRequest = objHttpContext.Request

FirewallIPAddress = objHttpRequest.ServerVariables("REMOTE_HOST")

There it is. Just add it to the web service method.
 
Try this:

<%
Option Explicit

Dim m_strExternalIP
Dim m_strInternalIP

m_strExternalIP = getExternalIP()
m_strInternalIP = Request.ServerVariables("LOCAL_ADDR")

function getExternalIP()
Const m_IP = "http://www.ShowMyIP.com/xml"
Dim objXML
Set objXML = CreateObject("MSXML2.DomDocument")
with objXML
.resolveExternals = true
.async = false
.load(m_IP)
getExternalIP = .documentElement.SelectSingleNode("ip").text
end with
Set objXML = Nothing
end function

%>

This was the only way to get my true IP.

Hope this helps:

Raul Costa
nospan_jrpcosta_at_hotmail_dot_com (Remove nospan_ and replace _at_ with @
and _dot_ with . )
 
Back
Top