2009年6月15日 星期一

簡易的掃Port程式

小弟最近在學Java Socket,而Socket主要就是在做網路的相關操作,而以下是一個簡單的檢查電腦Port是否開啟的小程式:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import java.net.*;
import java.io.*;

/**
*
* @author 111
*/
public class ScanPort_DOS {

public ScanPort_DOS() {
for (int i = 0; i < 1025; i++) {
try {
Socket sk = new Socket("127.0.0.1", i);
System.out.println("Port:" + i + " Open");
} catch (IOException e) {
}
}
}

public static void main(String[] args) {
new ScanPort_DOS();
}
}

執行畫面如下:

沒有留言: