首页 > 编程语言 > 详细

java FindMyIP.java

时间:2019-03-18 21:09:03      阅读:247      评论:0      收藏:0      [点我收藏+]

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

java FindMyIP.java

原文:https://www.cnblogs.com/lindows/p/10554850.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!