批处理如何获得系统ip地址并赋值变量
2个回答
2013-08-09
展开全部
单纯批处理不能获得外网IP,可以借助VBS,@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
>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
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家国内优质海外HTTP代理商,拥有一个庞大的IP资源池,覆盖200多个地区,IP数量大且匿名度高。其优点还包括超高并发、稳定高效、技术服务等特点,同时提供HTTP、HTTPS以及SOCKS5协议支持。此外,Sto...
点击进入详情页
本回答由Storm代理提供
展开全部
@echo off&setlocal enabledelayedexpansion
@title 批处理 获得系统IP地址并赋值变量
ipconfig>$
>$1 (findstr "IPv4 地址" "$") & move $1 $
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find/i "IPv4 地址"') do (
set "str_ip=%%a" & set str_ip=!str_ip: =!)
echo !str_ip!
pause>nul
从大神那看到一些回答,自己套出来的!反正我一般了解BAT,其它很多语言不懂了!
@title 批处理 获得系统IP地址并赋值变量
ipconfig>$
>$1 (findstr "IPv4 地址" "$") & move $1 $
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find/i "IPv4 地址"') do (
set "str_ip=%%a" & set str_ip=!str_ip: =!)
echo !str_ip!
pause>nul
从大神那看到一些回答,自己套出来的!反正我一般了解BAT,其它很多语言不懂了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询