• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3895
  • Last Modified:

DOS command to get WAN IP


We have several clients who are on dynamic IPs from their ISPs.  I am looking for a way to get the current IP from a server / network that is behind a firewall without actually being on that network.

My first thought was to run a scheduled task which was a batch file as follows:
@echo off
date /t >clientip.txt
time /t >>clientip.txt
ipconfig /all >>clientip.txt
ftp -s:ipftp.txt
ipftp.txt contents:

open ftp.mydomain.com
cd ips
put clientip.txt
This would give me a text file on an external source where I could see the current status of the network IP.  The catch is, ipconfig /all only give me the network IP (192.168. blah blah blah ) not the WAN IP.

Does anyone know a DOS command I can use in the batch that will give me the WAN IP
 -- OR --
another solution entirely that will give me the IP without being there.

Your prompt attention would be appreciated... I really need this ASAP!


  • 2
1 Solution
Hi NetteS,

Take a look at DynDNS - http://www.dyndns.org/services/dyndns/
This will create a DNS domain name, such as "myserver.dyndns.org" that will always point to the PC or Server's IP

You will need to install a small client app on the machine itself - details on the above webpage.

This means that you can just connect to the machine by the DynDNS domain name.

I hope that this helps.
You can do that with wget.exe, independently of the WAN router that's used (and assuming that there's no proxy involved). Don't get too confused about all the stuff you can do with wget; all you really need is wget.exe.
This script will then retrieve a html page with your current IP address, and set the variable WanIP accordingly.

GNU wget

@echo off
set URL=http://checkip.dyndns.org/index.html
:: *** The path to wget, if necessary (including the trailing backslash):
set wgetPath=D:\Programme\wget\

set TempFile=%~dpn0.html
if exist "%TempFile%" del "%TempFile%"
:: *** Retrieve the html document with the current IP address:
"%wgetPath%wget.exe" %URL% -O "%TempFile%"
:: *** Extract the current IP; this relies strongly on the current format of the source:
for /f "tokens=13 delims=<>: " %%a in ('type "%TempFile%"') do set WanIP=%%a
echo Current WanIP: [%WanIP%]
Hi.  Thanks for the "A".  Glad I could help :-)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now