本帖最后由 lovealei 于 2011-8-25 09:08 编辑
下面这段代码 是获取外网IP并赋值给变量的- @echo off
- >html.vbs echo set http=createobject("Microsoft.XMLHTTP")
- >>html.vbs echo Set objfs=CreateObject("scripting.filesystemobject")
- >>html.vbs echo Set objf=objfs.CreateTextFile("html.txt",True)
- >>html.vbs echo url=" http://ip.loveroot.com/"
- >>html.vbs echo http.open "get",url,false
- >>html.vbs echo http.send
- >>html.vbs echo zhi=zhuanghuan(Http.responsebody)
- >>html.vbs echo s=(zhi)
- >>html.vbs echo objf.write s
- >>html.vbs echo Function zhuanghuan(vIn)
- >>html.vbs echo strReturn = ""
- >>html.vbs echo For i = 1 To LenB(vIn)
- >>html.vbs echo ThisCharCode = AscB(MidB(vIn,i,1))
- >>html.vbs echo If ThisCharCode ^< ^&H80 Then
- >>html.vbs echo strReturn = strReturn ^& Chr(ThisCharCode)
- >>html.vbs echo Else
- >>html.vbs echo NextCharCode = AscB(MidB(vIn,i+1,1))
- >>html.vbs echo strReturn = strReturn ^& Chr(CLng(ThisCharCode) * ^&H100 + CInt(NextCharCode))
- >>html.vbs echo i = i + 1
- >>html.vbs echo End If
- >>html.vbs echo Next
- >>html.vbs echo zhuanghuan = strReturn
- >>html.vbs echo End Function
- html.vbs
- for /f "tokens=4 skip=2 delims= " %%i in ('find /i "结果:" html.txt') do set ip=%%i
- echo 您的iP地址为
- echo %ip%
- del html.txt
- del html.vbs
- @echo off
- for /f "tokens=15" %%i in ('ipconfig ^| find /i "ip address"') do set ip=%%i
- echo 内网IP
- echo %ip%
- pause
复制代码 单独存成一个文件执行是没有问题的,但如果加在一个批处理里面就提示 : ECHO 处于关闭状态 ,
此时
echo 您的iP地址为
echo %ip%
结果是
echo 您的iP地址为
echo ECHO处于关闭状态 |