내 대학 프로젝트에 IDS
을 개발해야합니다. 스니퍼 및 알고리즘에 대한 Java 코드를 사용할 수 있습니다. 1GB 이더넷 트래픽/초를 지원하도록 설정해야합니다. 이렇게하려면 multi-threading
을 통합하여 듀얼 코어 시스템에서 코드를 실행할 계획입니다. IP
을 기준으로 각 클라이언트에 대해 별도의 스레드를 만들려고합니다. 프로그램의 주요 기능은 packetLoader
{packetReciever
} 클래스의 openInterface()
메서드를 호출합니다. 방법 openInterface()
은 NIC
인터페이스를 열고 패킷 캡처를 시작합니다. 이 방법을 openInterface()
으로 변경해야 multi-threading
을 포함해야합니까? 어느 시점에 스레드를 만들어야합니까? 어떤 매개 변수를 기반으로 별도의 스레드를 만들어야합니까? 필요한 도구를 어떻게 구현해야합니까? multi-threading
? 나는 각 클라이언트 (IP 주소)에 대한 새로운 스레드를 생성 할 경우IDS의 멀티 스레딩
건배 :)
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);
}
}