Saturday, February 4, 2017

ARP Simulation

This program will find Physical Address for the given IP address. 


/* Sample arp.txt file generated using arp -a command
  192.168.3.3           f4-f4-9c-18-bb-4b     dynamic   
  192.168.3.2           ca-f8-87-a3-ee-20     dynamic   
  192.168.90.255        ff-ff-ff-ff-ff-ff     static    
  221.0.0.251           03-01-ef-00-ff-fc     static    
  29.253.251.20         02-01-ed-ff-00-fa     static
*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
  FILE *f1, *fopen();
  int ch;
  char str1[80], *token;
  const char str[80] = "", s[2] = " ";
  f1 = fopen("arp.txt","r");
  if ( f1 == NULL )     /* check does file exist*/ 
 
printf("Cannot open file for reading \n" ); 
exit(1);    
 
  while(fgets(str1,80,f1)!=NULL){
  token = strtok(str1,s);
  while (token != NULL){
      if (strcmp(token,"192.168.3.2") ==0)
  {
  token = strtok(NULL, s);
  printf("Your Physical address is %s",token);
      }
      else
      token = strtok(NULL, s);
    }
  }
  fclose(f1);
  return 0;
}

Output of the program

Your Physical address is ca-f8-87-a3-ee-20


No comments:

Post a Comment