IDS
大学のプロジェクト用に開発する必要があります。スニファとアルゴリズムの Java コードを利用できます。毎秒 1 GB のイーサネット トラフィックをサポートするには、有効にする必要があります。そのためにmulti-threading
、コードを組み込み、デュアル コア マシンで実行する予定です。に基づいて、クライアントごとに個別のスレッドを作成するつもりですIP
。プログラムのメイン関数はopenInterface()
、クラスpacketLoader
{implements packetReciever
} のメソッドを呼び出します。メソッドはインターフェイスをopenInterface()
開き、NIC
パケットのキャプチャを開始します。この方法を変更openInterface()
して組み込む必要がありmulti-threading
ますか? どの時点でスレッドを作成し始める必要がありますか? どのパラメーターに基づいて、個別のスレッドを作成する必要がありますか? 必要なものをどのように実装すればよいですmulti-threading
か?
乾杯:)
public void openInterface(String filter, int numOfPackets){
try {
if (!devName.startsWith(NIC_NAME_PREFIX)) {
if(numOfPackets == -1)
packetSamplingRatio = 1;
else {
packetSamplingRatio = numOfPackets/(double)totalPcapFilePackets;
}
}
//JpcapCaptor captor = null;
if (devName.startsWith(NIC_NAME_PREFIX)) {
System.err.println(".........inside openinterface");
NetworkInterface[] devicesList = JpcapCaptor.getDeviceList();
System.err.println(".........inside openinterface 2");
String nicName = devName.substring(NIC_NAME_PREFIX.length());
int nicID = -1;
for (int i = 0; i < devicesList.length; i++) {
System.err.println(".........inside openinterface 3");
if (devicesList[i].name.equals(nicName)){
System.err.println("Device no:" + i + "=" +devicesList[i].name);
System.err.println("capturing on device= " + devicesList[i].name);
nicID = i;}
}
if (nicID >= 0){
captor = JpcapCaptor.openDevice(devicesList[1],
NIC_SNAPLEN, true, NIC_TIMEOUT);
System.err.println(".........Device is open for packet capturing with");
System.err.println("NIC_SNAPLEN = " + NIC_SNAPLEN + " and NIC_TIMEOUT=" + NIC_TIMEOUT);
}
else {
System.err.println("Network interface " + nicName
+ "cannot be found!");
System.err.println("Availabel NICs:");
for(int k=0; k<devicesList.length; k++) {
System.out.println("- " + devicesList[k]);
}
System.exit(1);
}
} else {
System.err.println(".........inside else");
captor = JpcapCaptor.openFile(devName);
}
if (filter != null){
captor.setFilter(filter, true);
;
}// Start reading packets
System.err.println(".........filter checked");
//PacketStorage ps = new PacketStorage();
//captor.loopPacket(numOfPackets, this);
//captor.processPacket(numOfPackets, this);
for(int j =0; j<numOfPackets ; j++){
captor.getPacket();
System.err.println(".........captured packet" + j);
}
System.err.println(".........after capture.looppacket");
}
catch (IOException e) {
System.err.println("Exception in openDevice " + e);
System.exit(1);
}
}