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

  • 相关阅读:
    bzoj 2618: [Cqoi2006]凸多边形
    BZOJ 4556 [Tjoi2016&Heoi2016]字符串
    BZOJ 4850 [Jsoi2016]灯塔
    BZOJ 2956: 模积和
    PHP 正则表达式
    Linux Centos6.5安装redis3.0 和phpredis
    linux 删除过期文件
    THINKPHP报错 _STORAGE_WRITE_ERROR
    THINKPHP 部署nginx上URL 构造错误
    Linux 修改mysql密码
  • 原文地址:https://www.cnblogs.com/lindows/p/10554850.html
Copyright © 2011-2022 走看看