windows获取ip

环境:windows、vbs

1、新建txt拷贝内容到文件,修改文件后缀名vbs,双击即可执行

Set WshShell = WScript.CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("ipconfig.exe")
Set oStdOut = oExec.StdOut
ip = ""
Do Until oStdOut.AtEndOfStream
strLine = oStdOut.ReadLine
 
If InStr(strLine, "IPv4 地址") > 0 Then
 
ip = Mid(strLine, InStr(strLine, ":") + 2)
Exit Do
End If
Loop

If ip = "" Then
MsgBox "获取本地连接IP地址失败!", vbExclamation, "错误"
WScript.Quit
Else
MsgBox ip, vbExclamation, "本地连接IP地址!"
End If

WScript.Quit

 

posted @ 2020-08-06 20:00  苍茫宇宙  阅读(622)  评论(0编辑  收藏  举报