IT Notes : Use nslookup to monitor the ip address of a web site

nslookup is a windows command line tool to get the ip address of a web site .

Below is the syntax for looking up the ip address of www.abovethcloud.com

C:\Users\User>nslookup -type=A www.abovethcloud.com

Server:  dns.google

Address:  8.8.8.8


Non-authoritative answer:

Name:    www.abovethcloud.com

Address:  155.248.183.49


If we need to monitor the address of www.abovethcloud.com frequently,  we can use a   Windows batch file to accomplish the task. After finishing the batch file, the ip address is stored to log file with file name YYYYHHMMSS.log.

First check the date output format

C:\Users\User>date

The current date is: 13/01/2023 Fri

Enter the new date: (dd-mm-yy)

and time output format :

C:\Users\User>time

The current time is: 20:15:55.19

Enter the new time:

The date string format is "DD/MM/YYYY Fri"

DD is at position 0 to 1

MM is at position 3 to 4

YYYY is at position 6 to 9

Similarly, the time output format is HH:MM:SS.XX

We can get the hour value at position 0 to 1, minute value at position 3 to 4 and second value at 6 and 7, assume that the sub-second value is ignored.

Below is the code for the batch file

echo on

rem get the year value from date string and store it to CUR_YYYY

set CUR_YYYY=%date:~6,4%

rem echo %CUR_YYYY%

rem get the month value from date string and store it to CUR_MM

set CUR_MM=%date:~3,2%

rem echo %CUR_MM%

rem get the day value from date string and store it to CUR_DD

set CUR_DD=%date:~0,2%

rem echo %CUR_DD%

set CUR_HH=%time:~0,2%


if %CUR_HH% lss 10 (set CUR_HH=0%time:~1,1%)

rem echo %CUR_HH%

set CUR_NN=%time:~3,2%

set CUR_SS=%time:~6,2%

set CUR_MS=%time:~9,2%

set SUBFILENAME=%CUR_YYYY%%CUR_MM%%CUR_DD%-%CUR_HH%%CUR_NN%%CUR_SS%

rem mkdir %SUBFILENAME%

nslookup -type=A  www.above.com  >%SUBFILENAME%.log


Comments

Popular posts from this blog

旅遊筆記 : 吉隆坡前往檳城交通方式及網上購買馬來西亞KTM火車票教學

旅遊筆記 : 馬來西亞電動 Platinum ETS 列車初體驗

閒遊深水灣、淺水灣觀無敵海景,順走赤柱古道訪老虎坑、獅子坑古石橋尋歷史。