s
ganymed-ssh2-build210.jar
package com.iteye.lindows.ssh.ip;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import sun.rmi.runtime.RuntimeUtil;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class FindMyIP {
public static void main(String[] args) {
String userName = "root";
String password = "root";
for (int i = 1; i < 256; i++) {
try {
String server = "10.49.7.";
server += i;
//Process process = Runtime.getRuntime().exec("telnet "+server+" 22");
Connection conn = new Connection(server);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(
userName, password);
if (isAuthenticated == false) {
continue;
}
Session sess = conn.openSession();
sess.execCommand("hostname");
System.out.println(server + "Here is some information about the remote host:");
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true) {
String line = br.readLine();
if (line == null) {
break;
}
System.out.println(line);
}
System.out.println("ExitCode: " + sess.getExitStatus());
sess.close();
conn.close();
} catch (Exception e) {
System.out.println("timeout"+e);
}
}
}
}
end