public List<String> call() throws IOException { List<String> names = new ArrayList<String>(); Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); while (nis.hasMoreElements()) { NetworkInterface ni = nis.nextElement(); LOGGER.fine("Listing up IP addresses for " + ni.getDisplayName()); Enumeration<InetAddress> e = ni.getInetAddresses(); while (e.hasMoreElements()) { InetAddress ia = e.nextElement(); if (ia.isLoopbackAddress()) { LOGGER.fine(ia + " is a loopback address"); continue; } if (!(ia instanceof Inet4Address)) { LOGGER.fine(ia + " is not an IPv4 address"); continue; } LOGGER.fine(ia + " is a viable candidate"); names.add(ia.getHostAddress()); } } return names; }
/** Used for CLI binding. */ @CLIResolver public static Computer resolveForCLI( @Argument(required = true, metaVar = "NAME", usage = "Slave name, or empty string for master") String name) throws CmdLineException { Jenkins h = Jenkins.getInstance(); Computer item = h.getComputer(name); if (item == null) { List<String> names = new ArrayList<String>(); for (Computer c : h.getComputers()) if (c.getName().length() > 0) names.add(c.getName()); throw new CmdLineException( null, Messages.Computer_NoSuchSlaveExists(name, EditDistance.findNearest(name, names))); } return item; }