Monday, June 16, 2008

4Test - Getting IP address

In automation, sometimes we need to find the tricks to achieve it. Like that I have done to find the IP address of a machine. You can see the following code snippet.

Silktest code - To find IP address of a system

[+] public String GetIpAddress(String sMachineName) [ ] //To get IP Address for the particular machine in Network [ ] List of String lsOutput [ ] String sCommand [ ] String sTemp, sItem [ ] String sResult = NULL [ ] Boolean bResult = FALSE [ ] Integer iPos1, iPos2 [ ] [ ] sCommand = "ping -a {sMachineName}" [ ] Sys_Execute (sCommand,lsOutput) [ ] [ ] //ListPrint (lsOutput) [-] for each sItem in lsOutput [-] if (MatchStr("*pinging*", sItem)) [ ] bResult = TRUE [ ] break [ ] [-] if (bResult) [ ] iPos1 = StrPos ("[", sItem) [ ] iPos2 = StrPos ("]", sItem) [-] if ((iPos1 > 0) && (iPos2 > 0)) [ ] sResult = SubStr(sItem,iPos1+1, iPos2-iPos1-1) [ ] Print ("Found IP Address: {sResult}") [ ] return sResult

No comments: