发布网友 发布时间:2022-04-22 00:30
共5个回答
热心网友 时间:2022-07-14 10:07
for /f "tokens=1,2* delims=:" %a in ('ipconfig ^|findstr "IP Address"') do set ip=%b
echo %ip%
不过这种方法有局限性,因为你如果有多个网卡,或者只有一张网卡,而你的ipconfig命令中显示的最后一行IP Address不是你想要的地址(有时机器安装了IPV6协议)
如果是写在批处理文件中,可以:
for /f "tokens=1,2* delims=:" %%a in ('ipconfig ^|findstr "IP Address"') do set ip=%%b
echo %ip%
热心网友 时间:2022-07-14 10:07
这个批处理能把你的ip写在屏幕上,但是怎么弄到文件里我就*为力了
----------------------------------------------------------------------------------------
@echo off
<"%~f0" more +7 >tmp.vbs
cscript /nologo tmp.vbs
pause
del tmp.vbs
goto :eof
set http=createobject("Microsoft.XMLHTTP")
ipp="http://www.ip138.com/ip2city.asp"
http.open "get",ipp,false
http.send
ss=bytes2BSTR(Http.responsebody)
intStrA = InStr(1,ss,"[",1)+1
sss=mid(ss,intStrA)
intStrB = InStr(1,sss,"]",1)-1
ss=mid(ss,intStrA,intStrB)
wscript.echo ss
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
-----------------------------------------------------------------------------------------------------------
如果直接用ipconfig>%ipaddr%的话得到的又不是单纯的ip···
热心网友 时间:2022-07-14 10:07
不明白你的%ipaddr%意思,不过获取的命令 ipconfig /all >c:\\ip.txt
find \"IP Address\" ip.txt >>>%tm_ini_path%\tm.ini 这样试试 看看思路对不对
热心网友 时间:2022-07-14 10:08
试试这样子:
@echo off
SETLOCAL
set add=192.168.1.1
echo %add%
endlocal
echo . &pause
热心网友 时间:2022-07-14 10:09
@echo off
FOR /F "eol=; tokens=2,14,15,16 delims=, " %%i in ('IPCONFIG') do @IF "%%i"=="Address." ECHO %%k>>tm.ini
PAUSE