February 11, 2008
Tip14 - Getting IP address of a machine
Below code snippet is useful to find IP address of a system. It is based on Sys_execute command.
[+] 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
1 comments:
Just now I have entered into the magic world of silk test as automation test engineer. I find your blog to be very very useful. Please continue your good work and help novice like me to learn new things.
Post a Comment