Ask a question »

Batch File to get IP address

May 2015

An IP (Internet Protocol) address is used to identify your computer, router or any other network devices in your network or internet. A typical home network router has two IP addresses: one for external internet (WAN) and the other for the internal home (LAN) connection. A router is a hardware device which uses software for performing the routing of data packets in an internal network. All routers are hardware firewalls. Batch file is a text file which contains a set of commands for the operating system of the computer. To get the router IP address from a batch file you need to create two files- getip.js and GetIP.bat by writing the right codes. Run the .bat file which will create .txt file called IP.txt containing your external IP address or internet IP address.

Batch File to get IP address



Issue


I have a slight problem and am looking for some help!!

OK, I need a bat file to run daily to tell me what my "ADSL" Router's IP is (ie. 91.80. etc etc) and not the local IP of 192.168 etc.

This is because Sky (ISP) does not support static IPs so this changes when the router gets rebooted.

Solution



Please follow these instructions:
  • Right click desktop and select new txt document.
  • Open the newly created .txt file and paste the following code into it:


var request = new ActiveXObject("Msxml2.XMLHTTP");   
var notyetready = 1;   

request.onreadystatechange=function()   
{   
if(request.readyState==4)   
{   
WScript.Echo(request.responseText);   
notyetready = 0;   
}   
}   

request.open( "GET", "http://www.whatismyip.com/automation/n09230945.asp", true );   
request.send(null);   

while( notyetready )   
{   
WScript.Sleep( 100 );   
} 
  • Safe your new .txt file. Then rename it: getip.js


Now make another new .txt file and paste this into it:

cscript getip.js >ip.txt 
  • Safe the file and then rename it: GetIP.bat
  • Run the .bat file and it will create a .txt file called IP.txt which contains your 'internet IP address' or external IP address.

Note


Thanks to Flo-TLSC for this tip on the forum.
For unlimited offline reading, you can download this article for free in PDF format:
Batch-file-to-get-ip-address.pdf

See also

In the same category

Published by aakai1056. - Latest update by Virginia Parsons
This document entitled « Batch File to get IP address » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.