How To Simulate Telnet Session in Java 텔넷 세션을 시뮬레이트하는 방법을 자바
Often we come across procedures which need to be performed by issuing commands in a telnet session. 종종 우리는 전체 절차를 수행할 필요가 텔넷 세션에서 명령을 발행합니다. It is relatively easy to do it manually but is definitely not suitable for automation. 그것은 상대적으로 쉬운 일은 아닙니다 적합하지 않다는 자동화를 수동으로하지만 분명히합니다. Let’s see how you can easily automate such tasks using Java software. 어디 보자 같은 작업을 자동화할 수있는 방법에 쉽게 자바 소프트웨어를 사용합니다. Sample code included. 예제 코드를 포함합니다.
Here is the core code: 여기서의 핵심 코드 :
// Conversation; Simulating telnet session with James server / / 회화, 제임스 서버로 텔넷 세션을 시뮬레이트
readLines(r, 3); readlines (연구, 3);
writeLine(w, login); writeline (폭, 로그인);
readLines(r, 1); readlines (연구, 1);
writeLine(w, password); writeline (폭, 비밀 번호);
readLines(r, 1); readlines (연구, 1);
writeLine(w, SHUTDOWN); writeline (폭, 종료);
readLines(r, 1); readlines (연구, 1);
readLines() reads and discards specified number of lines (response). readlines () 읽기 및 폐기 지정된 수의 행 (응답).
Here are the key functions: 주요 기능은 다음과 같습니다 :
/** Read and discard count lines from BufferedReader r */ public static void readLines(BufferedReader r, int count) throws IOException { for(int i = 0;i < count;i++) { String t = r.readLine(); if(DEBUG) System.out.println(t); } } /** Write out to BufferedWriter w and flush */ public static void writeLine(BufferedWriter w, String out) throws IOException { w.write(out + CRLF, 0, (out + CRLF).length()); w.flush(); } / ** bufferedreader 연구에서 읽기 및 폐기 카운트 라인 * / 공공 정적 무효 readlines (bufferedreader 연구, int 수) ioexception (에 대한 예외 (int 전 = 0; 나는 <카운트; 나는 + +) (문자열을 t = r.readline (); 만약 (디버그) system.out.println (t);)) / ** bufferedwriter 승 및 플래시를 작성 * / 공공 정적 무효 writeline (bufferedwriter 승, 문자열 아웃) 예외 ioexception (w.write (아웃 + crlf, 0 , (아웃 + crlf). 길이 ()); w.flush ();) You can download the code 코드를 다운로드하실 수있습니다 here 여기에 . 합니다. It is used to shutdown Apache James Mail Server. 그것을 사용하여 아파치 제임스 메일 서버를 종료합니다. The utility is fully described along with the options in - 이 유틸리티는 완전하게 설명과 함께 옵션이 - Shutdown Apache James Mail Server - Java Utility 아파치 제임스 메일 서버를 종료 - 자바 유틸리티
Filed under 밑에 Headline News 헤드 라인 뉴스 , How To 하는 방법을 , Java Software 자바 소프트웨어 , Tech Note 기술 참고 사항 | |
| |
RSS 2.0 rss 2.0 | |
Email this Article 전자 우편이 문서
You may also like to read 같은를 읽을 수있습니다 |





































April 17th, 2006 at 12:45 am 2006년 4월 17일에서 오전 12시 45분
good 좋다
March 13th, 2008 at 10:59 pm 2008년 3월 13일에서 오후 10시 59분
Hey, 어이,
I have a question re the above code. 나는 질문이 다시 위의 코드합니다. I attempted to modify this for use with a Cisco Catalyst 3500 swtich to return the the mac address tale using the “sh mac-address-table” command. 나는 이것을 수정을 시도 시스코 촉매를 사용하기 위해 3500 swtich 이야기를 반환합니다 매킨토시 주소를 사용하여 "쉿 맥 - 주소 - 테이블을"명령을합니다. However, I’m having a problem where, using the above code, i need to specify the number of lines to read back. 그러나, 나는 문제가 어디에, 위의 코드를 사용하여, 전 라인을 읽을의 개수를 지정해야합니다 위로합니다. But, depending on the amount of clients physically collected into the switch, the number varies. 하지만, 육체적으로 수집된의 고객에 따라 금액이 스위치로 번호가 다릅니다. I attempted to write a while((line = in.readLine()) != null) { .. 을 시도하는 동안 나는 쓰기 ((행 = in.readline ())! = 널) (.. } block of code but tis fails where, once it reaches the end, it sits there as if expecting more. ) 블록의 코드가 실패하지만 절대적 어디에, 한번에 도달 결국, 그것이 앉고 다른 사람이 마치를 기대합니다. It never receives a NULL at the end. 결코 널 끝에 받는다.
In another attempt, i assumed the last line should contain a prompt. 또 다른 시도를 포함해야합니다 프롬프트의 마지막 줄에 나보다라고 생각합니다. However, this also failed. 그러나, 이것도 실패했습니다. It seems readLine() discards prompts but should replace them with NULL. 것 자체에 ()를 삭제 널 묻습니다 그러나 그들을 교체해야합니다. But this doesn’t seem to be true for me. 하지만이되지 않습니다 나를 위해 진실한 것 같습니다.
My question is this, is there a way to adapt your code so that it can read an unknown number of lines and store the output? 나의 질문은 이것이고, 귀하의 코드에 적응하는 방법이 있습니까 수 있도록 행 수를 알 수없는 읽기 및 저장의 출력?
Many Thanks, 많은 감사합니다,
A a