How to determine the IP address of local system?
Ofcourse, this is trivial. You open a command prompt and type IPCONFIG to see the ip address of the local system. On Linux System you would type ifconfig eth0 in a shell window to see the ip address in eth0. But how do we do this within QTP for automation purposes ? There are many ways. Below is one way to get the IP address.
Below is the code to obtain the ipaddress using WMI
Function LocalHostIPAddress()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set ColItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objitem In ColItems
strIP = Join(objitem.IPAddress, ",")
strIPAddress = strIP
Next
LocalHostIPAddress = strIPAddress
End Function
No comments yet.
Leave a Reply
-
Archives
- December 2010 (3)
- April 2009 (1)
- August 2008 (5)
- July 2008 (4)
- May 2008 (2)
- April 2008 (3)
- February 2008 (3)
-
Categories
-
RSS
Entries RSS
Comments RSS