【网络应用】批处理获取本机的公网IP地址

【方案一】BAT + VBS

 

@echo off set "URL=http://www.ip138.com/ip2city.asp" >%temp%/download.vbs echo Set objDOM = WScript.GetObject(WScript.Arguments(0)) >>%temp%/download.vbs echo Do Until objDOM.ReadyState = "complete" >>%temp%/download.vbs echo WScript.Sleep 100 >>%temp%/download.vbs echo Loop >>%temp%/download.vbs echo WScript.Echo objDOM.DocumentElement.OuterText for /f "tokens=2 delims=[]" %%a in ('cscript //nologo //e:vbscript %temp%/download.vbs "%URL%"') do ( set "PublicIP=%%a" ) echo,%PublicIP% pause

 

【方案二】BAT + wget.exe(GNU)

 

@echo off set "URL=http://www.ip138.com/ip2city.asp" for /f "tokens=2 delims=[]" %%a in ('wget -q "%URL%" -O -') do ( set "PublicIP=%%a" ) echo,%PublicIP% pause

 

【方案三】BAT + curl.exe(GNU)

 

 @echo off set "URL=http://www.ip138.com/ip2city.asp" for /f "tokens=2 delims=[]" %%a in ('curl -s "%URL%"') do ( set "PublicIP=%%a" ) echo,%PublicIP% pause

你可能感兴趣的:(网络应用,url,VBScript)