【QTP】获取本地IP地址

可以获取本地IP地址的脚本

print GetIP()

'获取本地IP地址
Function GetIP() 
    Dim objWMIService,colItems,objItem,objAddress
    Set objWMIService = GetObject("winmgmts://./root/cimv2")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    For Each objItem in colItems
        For Each objAddress in objItem.IPAddress
            If objAddress <> "" then
                GetIP = objAddress
                Exit For
            End If  
        Next
     Exit For
    Next
End Function

发表评论

电子邮件地址不会被公开。