The *n?x crowd likes ipecho.net, which is a lo-fat version. Even better is ipecho.net/plain. whatismyip.org is also lo-fat but performance/availability has been bad for some time now.
You're right, if you happen to know a URL that's known to map to the public IP you can use DNS, either directly or indirectly as you suggest via PING. However, in some cases PING won't be reliable. For example, suppose a small business is hosting its own web site, which is used both externally and internally. Internal DNS could be set to go straight to the LAN address of the web server. So, querying
www.somedomain.com while on the local network would return a local IP address.
You can get a correct answer by directly querying DNS, and forcing the query to use an external/public DNS server:
nslookup [URL to look up] [DNS server to use]
nslookup www.somedomain.com 8.8.8.8
All this presupposes a URL is available, which may not be the case for individual users, small businesses, or any organization that has all its web services hosted by 3rd parties. Even if one exists, users may not know what it is. I don't know the OP's need for this, but if it's for anti-piracy or something similar, users may not be willing to give such a URL.
So, the most reliable way is to hit an external service like one of the sites listed earlier. Interestingly, this can be done in Windows PowerShell:
# Requires PowerShell 3.0 or later
# Windows 8.1 comes with 4.0 by default
# Windows 7 comes with 2.0 by default, but can be updated from http://www.microsoft.com/en-us/download/details.aspx?id=40855
$tmp=Invoke-WebRequest -URI http://ipecho.net/plain
$tmp.Content >Content.txt
# Parse Content.txt to get the IP address
>whatismyip.com works from inside many networks. But if the firewall is blocking web access, the you're pretty much out of luck, unless you know the url to hit the network from outside. In that case a PING will work, even if it isn't returned: the PING program first resolves the address, which is then listed for you.
>
>Hank
>
>>What are the best commands to use in order to get the
>>
>>- Public (router) IP Address?
>>- Computer's IP Address within the Network (listed via ipconfig)?
>>
>>Also is there a command to get the Host's Name and Host's Location?
>>(as some of the website are able to show).
>>
>>Thanks
Regards. Al
"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov
Neither a despot, nor a doormat, be
Every app wants to be a database app when it grows up