cancel
Showing results for 
Search instead for 
Did you mean: 

Ping a machine name and verify IP address

SOLVED
Contributor

Ping a machine name and verify IP address

I have a requirement to ping a machinename and fetch its IP address as a step in one of my testcases. Wanted to know if testcomplete can perform operations like this. I just have the license for web module and use python for scripting on testcomplete.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Ping a machine name and verify IP address

Yes, This can be possible using the WshShell

A sample code to read the output of ping

 

function getPingResult(serverName)
{
  var oShell = getActiveXObject("WScript.Shell"); // Or oShell = WshShell
  var oExec = oShell.Exec("powershell -command  ping " + serverName );
  oExec.StdIn.Close(); // Close standard input before reading output

  // Get PowerShell output
  var strOutput = oExec.StdOut.ReadAll();
  // Trim leading and trailing empty lines
  strOutput = aqString.Trim(strOutput, aqString.stAll);

  // Post PowerShell output to the test log line by line
  aqString.ListSeparator = "\r\n";
  for (var i = 0; i < aqString.GetListLength(strOutput); i++)
  {
    Log.Message(aqString.GetListItem(strOutput, i));
  }
}

Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

View solution in original post

2 REPLIES 2
Community Hero

Re: Ping a machine name and verify IP address

Yes, This can be possible using the WshShell

A sample code to read the output of ping

 

function getPingResult(serverName)
{
  var oShell = getActiveXObject("WScript.Shell"); // Or oShell = WshShell
  var oExec = oShell.Exec("powershell -command  ping " + serverName );
  oExec.StdIn.Close(); // Close standard input before reading output

  // Get PowerShell output
  var strOutput = oExec.StdOut.ReadAll();
  // Trim leading and trailing empty lines
  strOutput = aqString.Trim(strOutput, aqString.stAll);

  // Post PowerShell output to the test log line by line
  aqString.ListSeparator = "\r\n";
  for (var i = 0; i < aqString.GetListLength(strOutput); i++)
  {
    Log.Message(aqString.GetListItem(strOutput, i));
  }
}

Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

View solution in original post

Contributor

Re: Ping a machine name and verify IP address

Thank you

New Here?
Join us and watch the welcome video:
Final Interview in the Series
API_testing_mistake#7