How do You Create a Black Hole Attack in Ns2

Through this article “how do you create a black hole attack in network simulator 2?” we have provided the essential information about creating the black hole attack in network simulator 2.

Integrate Blackhole Patch into Ns2

To integrate the patches based on blackhole into network simulator 2, we have to follow the below mentioned steps.

  • As the first process, we have to download the patch from the below mentioned URL

Link to Download Blackhole Patch
  • Then, paste the downloaded blackhole patch in the folder which is named as ns-2.35 folder
  • Following that, we have to implement the below mentioned commands to ingrate the patches with Ns-2.35

patch -p1 -t < Blackhole.patch

Create Blackhole Attack in Ns2

Most significantly, we have to use the below mentioned source code to create and delete the blackhole attack in network simulator 2.

Tcl&amp;tcl = Tcl::instance();

if(strncasecmp(argv[1], “id”, 2) == 0) {

tcl.resultf(“%d”, index);

return TCL_OK;


if(strcmp(argv[1], “blackhole1”) == 0) {

malicious1= index;

printf(“malicious %d”, malicious1);

return TCL_OK;


if(strcmp(argv[1], “blackhole2”) == 0) {


printf(“malicious %d”, malicious2);

return TCL_OK;


As the final note, we are assuring that we provide the complete research support for the research scholars. So, reach us and aid more.