zoukankan      html  css  js  c++  java
  • java FindMyIP.java

    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

  • 相关阅读:
    算法:拓扑排序
    【欧拉计划2】Even Fibonacci numbers
    机房收费系统之模版方法使用
    VC运行时库
    数据库学习(6)——基本查询操作
    Attribute与Property的区别
    记C++类成员访问权限符二三事
    大年初五去颐和园
    2013年第6周六农历除夕下午
    大年初四晚上睡前
  • 原文地址:https://www.cnblogs.com/lindows/p/10554850.html
Copyright © 2011-2022 走看看