Pages

Wednesday, 19 October 2011

QTP Script: Get your machines IP address


' =============================================================
' function: GetIPAddress
' desc : Returns the IP address of the PC
' params : Void
' returns : IP Address
' =============================================================
Function GetIPAddress()

' get the ip addresses
Set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
                  ("select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

' for each item in the collection
For Each IPConfig in IPConfigSet

    ' if the item isn't empty
    If Not IsNull(IPConfig.IPAddressThen

        ' loop through the addresses
        For i = LBound(IPConfig.IPAddressto UBound(IPConfig.IPAddress)

            ' set the return alue
            ipAddr = IPConfig.IPAddress(i)

        Next

    End If

Next

' destroy the object
Set IPConfigSet = Nothing

' return the ip
GetIPAddress = ipAddr 

End Function ' GetIPAddress


0 comments:

Post a Comment