看板 java 關於我們 聯絡資訊
import java.io.*; class test { public static void main(String[] args) { try { String cmd = "netstat -n"; String findIP="IP"; Process child = Runtime.getRuntime().exec(cmd); // 獲得輸出 InputStream child_in = child.getInputStream(); int c; while ((c = child_in.read()) != -1) { // System.out.println("kkk"); System.out.print((char)c); //if((char)c==findIP) } child_in.close(); } catch (IOException e) { System.err.println(e); } } } 這個程式執行起來就跟在console mode打 netstat -n 一樣 會顯示出所有的連線情形 我想檢查getInputStream 裡面有沒有某個IP 但是read()是一個byte一個byte的去讀取 沒辦法用一個if(stringA==IP) 去做判斷式 其他有關getInputStream的read實際上也還是一個byte這樣讀進來 只不過先暫存到array 想請問有沒有什麼辦法?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.174.35.92
ogamenewbie:全讀入StringBuilder 轉String 用正規式抓ip 比對 12/10 01:44
GGsov:謝謝...卡在不知道怎讀怎判斷 Orz 12/10 21:08