haripotter’s technorati

Just another WordPress.com weblog

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

Advertisement

December 28, 2010 - Posted by | HP Quality Center and QTP

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.