IP Routing 是 OSI Layer 3 (Network) 在處理的事情, DNS Name 則是 OSI Layer 7 (Application) 才能處理的, 你把 Layer 7 的東西, 硬塞給 Layer 3 去吃, 叫他怎麼吞得下去?....
某些設firewall/routing rule的工具在遇到user輸入FQDN時會解成IP代入,但是遇到單一FQDN有多個A record時就糗了----到底是要以哪一個A record為準,還是要自動為每筆A record加一筆rule啊....
寫的batch就可以
@echo off
set "InputDomain=%1"
set "InputRouter=%2"
set "targetIP=pingerror"
if "%1" == "" goto :usage
if "%2" == "" goto :usage
for /f "tokens=2 delims=[]" %%F in ('ping -4 -n 1 %InputDomain%') do set "targetIP=%%F"
if %targetIP% == pingerror goto :end
echo Found "%1" IP : %targetIP%
echo route add %targetIP% mask 255.255.255.255 %2
@echo on & route add %targetIP% mask 255.255.255.255 %2
@goto :eof
:end
echo [%1] IP not found! & echo.
:usage
echo Usage : %0 DomainName YourRouter
echo Example: %0 google.com 192.168.0.1