純粹靠內建的指令沒有辦法,因為這是架構問題,作業系統不知道自己在網路的那裏?

但如果寫程式的人知道網路架構,則可以用程式(例如 wget )去抓取 IP 分享器上的資訊,或連線 http://checkip.dyndns.org/ 取得外部 IP。
所以一般撰寫BAT批次檔查詢對外IP是要借由某些工具才能查詢!


撰寫BAT批次檔查詢對外IP 批次檔如下:
@Echo Off
Color 0a
Mode con cols=48 lines=5
Set UD=2012/01/10 By Shyam
Rem 用途
Rem 取得本機電腦端連外真實IP
Rem 電腦需有 Wget 指令....
Wget myip.com.tw
For /f "tokens=6,4* delims=>" %%a in ('findstr "green" index.html') do echo %%a > index.html
For /f "tokens=2,1* delims=<" %%a in (index.html) do echo %%a > index.html
Cls
Echo.
Type Index.html
Echo.
Del Index.html
Pause

但是仍要提醒,如果有兩層以上的網路架構,就不一定適用!

arrow
arrow
    全站熱搜

    chunju 發表在 痞客邦 留言(0) 人氣()