Script to Test Ports

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search

//tcpPortTest(JSONArray jsa, String ip, String portsList, int timeout, int threads)

var utils = Java.type('ros.CROSUtils');
var jsonarray = Java.type('org.json.JSONArray')
var results=new jsonarray(true)
utils.tcpPortTest(results,"172.21.40.254","22-23,80,443,1000-1050",100,10)
log.warn("results.length:"+results.length());
for (var i=0;i<results.length();i++){
 var entry =results.getJSONObject(i);
 if (entry.getInt("response")>-1){
 log.warn("Response for port "+entry.getInt("port")+" in "+entry.getInt("response")+" ms");
 }else{
   log.warn("No response for port "+entry.getInt("port"));
 }
}