Created
August 5, 2022 19:20
-
-
Save dsta50/7e35a7f97ab621387437476f3cce98c9 to your computer and use it in GitHub Desktop.
[Windows Batch] DDNS (MyDNSJP)にグローバルIPアドレスを通知する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
rem --This Windows Batch file is tells DDNS (MyDNSJP) the global IP address | |
rem --Value | |
set ddnsid=userid | |
set ddnspass=password | |
set ddnsurl=https://www.mydns.jp/directip.html | |
set logfile=mydnsjp.log | |
set gipv4url=https://inet-ip.info/ip | |
rem --Main | |
echo. >> %logfile% | |
echo ----[%date% %time%]---- >> %logfile% | |
rem --Get Globle IP address info | |
curl %gipv4url% > gipv4.tmp | |
findstr "^[1-9]*\.[0-9]*\.[0-9]*\.[0-9]" gipv4.tmp > nul | |
if not %errorlevel%==0 ( | |
echo "(Error) Failed to get global IP address info" >> %logfile% | |
del gipv4.tmp | |
exit /b 1 | |
) | |
rem --Put the IP address in a variable | |
set /p gipv4=<gipv4.tmp | |
del gipv4.tmp | |
echo. >> %logfile% | |
rem --Update IP address to DDNS | |
curl "%ddnsurl%?MID=%ddnsid%&PWD=%ddnspass%&IPV4ADDR=%gipv4%" >> ddns.tmp | |
rem --NOTE:May be necessary to change the conditional expression | |
findstr "Login.and.IP.address.notify.OK\." ddns.tmp > nul | |
if not %errorlevel%==0 ( | |
echo "(Error) Failed to upload global IP address to DDNS" >> %logfile% | |
del ddns.tmp | |
exit /b 2 | |
) | |
echo ---Result LOG---- >> %logfile% | |
type ddns.tmp >> %logfile% | |
del ddns.tmp | |
echo. >> %logfile% | |
exit /b 0 |
Author
dsta50
commented
Aug 5, 2022
- 新規作成
- Windows 10で実施
- DDNS通知後の条件式に変更があるかも
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment