java连接telnet

	public boolean telnetMTA(String ip, int port){
		TelnetClient telnetClient = new TelnetClient();
		BufferedReader br = null;
		
		try {
			telnetClient.connect(ip, port);
			InputStream in = telnetClient.getInputStream();//220 ESMTP
			br = new BufferedReader(new InputStreamReader(in));
			
			if( SUCCESS.equals(br.readLine()) ){
				return true;
			}
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			
			try {
				if(br != null) br.close();
				if(telnetClient.isConnected()) telnetClient.disconnect();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		return false;
	}

你可能感兴趣的:(telnet)