The ExternalAddress property returns the IP address
assigned to the router that connects the local host to the Internet.
This is typically used by an application executing on a system in a
local network that uses a router which performs Network Address
Translation (NAT). In that network configuration, the
LocalAddress property will only return the IP address for the
local system on the LAN side of the network unless a connection has
already been established to a remote host.
This property can be used to determine the IP address assigned to the
router on the Internet side of the connection and can be particularly
useful for servers running on a system behind a NAT router. Note that
you should not assign the LocalAddress property to the value
returned by the ExternalAddress property. If the server is
running behind a NAT router, the router must be configured to forward
incoming connections to the appropriate address on the local network.
It may not be possible to determine the external IP address for the
local system for a number of reasons, particularly if it is behind a
firewall or uses a proxy server that restricts access to external
sites on the Internet. If you are using a VPN (Virtual Private Network),
this property will return the external IP address for the VPN adapter
and not your local network connection. The VpnAdapter property
can be used to obtain the name of the active VPN adapter and the
VpnAddress property can be used to determine the IP address
assigned to the adapter.
Checking this property value may cause the current thread to block
until the external IP address can be resolved and should never be
used in conjunction with asynchronous socket connections.