免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2622 | 回复: 6
打印 上一主题 下一主题

[网络管理] 寻求 sendARP下载地址,请大哥们帮忙,谢谢啦 [复制链接]

论坛徽章:
6
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-03 17:33:522015元宵节徽章
日期:2015-03-06 15:50:39IT运维版块每日发帖之星
日期:2016-01-11 06:20:00IT运维版块每日发帖之星
日期:2016-03-19 06:20:0019周年集字徽章-19
日期:2019-09-06 18:56:11
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-03-10 12:26 |只看该作者 |倒序浏览
寻求 sendARP下载地址,请大哥们帮忙,谢谢啦

论坛徽章:
0
2 [报告]
发表于 2003-03-10 13:01 |只看该作者

寻求 sendARP下载地址,请大哥们帮忙,谢谢啦

附加的文件中有sendarp的源码,自己编译.

  1. #include <stdio.h>;
  2. #include <ctype.h>;
  3. #include <stdlib.h>;
  4. #include <string.h>;
  5. #include <errno.h>;
  6. #include <netdb.h>;
  7. #include <sys/socket.h>;
  8. #include <arpa/inet.h>;
  9. #include <linux/if_ether.h>;
  10. #include <getopt.h>;

  11. #define ETH_HW_ADDR_LEN 6
  12. #define IP_ADDR_LEN 4
  13. #define ARP_FRAME_TYPE 0x0806
  14. #define ETHER_HW_TYPE 1
  15. #define IP_PROTO_TYPE 0x0800

  16. #define DEBUG 1

  17. char usage[] = {"sendarp: send an arp packet\n\
  18.     usage: sendarp [-?] [-v] [-t message_type] [-i interface]\n\
  19.                    [-p sender_protocol_address] [-P target_protocol_address]\n\
  20.                    [-h sender_hardware_address] [-H target_hardware_address] [-v]\n\
  21. \n\
  22.     -?    display this message
  23. \n\
  24.     -v    verbose                         Default: not verbose\n\
  25.               Be verbose\n\
  26. \n\
  27.     -t    message type               Default: 1\n\
  28.               Identifies the purpose for this ARP packet\n\
  29.               1    ARP Request\n\
  30.               2    ARP Response\n\
  31.               3    Reverse ARP Request\n\
  32.               4    Reverse ARP Response\n\
  33.               8    Inverse ARP Request\n\
  34.               9    Inverse ARP Response\n\
  35. \n\
  36.     -i    interface                       Default: eth0\n\
  37.               Select an interface (eth1, lo, ppp0, whatever...)\n\
  38. \n\
  39.     -p    sender protocol address         Default: 0.0.0.0\n\
  40.               Identifies the ip address of the system issuing the ARP packet.\n\
  41. \n\
  42.     -P    target protocol address         Default: 0.0.0.0\n\
  43.               Identifies the ip address of the ARP packet's destination.\n\
  44. \n\
  45.     -h    sender hardware address         Default: 00:00:00:00:00:00\n\
  46.               Identifies the hardware address of the system issuing the ARP packet.\n\
  47. \n\
  48.     -H    target hardware address    Default: 00:00:00:00:00:00\n\
  49.               Identifies the hardware address of the ARP packet's destination.\n\
  50. \n\
  51.     Bugs:\n\
  52.           if you find any please email <jrs@abiogenesis.com>;\n\
  53.               thanks.
  54. \n\
  55.     Author(s):\n\
  56.           Derived from send_arp.c by Yuri Volobuev <volobuev@t1.chem.umn.edu>; 1997\n\
  57.           Modified by Jonthan R. Seagrave <jrs@abiogenesis.com>; 14 Sep 2000\n\
  58. \n"};

  59. struct arp_packet {
  60.         u_char dst_hw_addr[ETH_HW_ADDR_LEN];
  61.         u_char src_hw_addr[ETH_HW_ADDR_LEN];
  62.         u_short frame_type;
  63.         u_short hw_type;
  64.         u_short prot_type;
  65.         u_char hw_addr_size;
  66.         u_char prot_addr_size;
  67.         u_short type;
  68.         u_char sndr_hw_addr[ETH_HW_ADDR_LEN];
  69.         u_char sndr_ip_addr[IP_ADDR_LEN];
  70.         u_char rcpt_hw_addr[ETH_HW_ADDR_LEN];
  71.         u_char rcpt_ip_addr[IP_ADDR_LEN];
  72.         u_char padding[18];
  73. };

  74. void send_arp(char *src_ip, char *src_hw_addr, char *dst_ip, char *dst_hw_addr, char *interface, u_short type);
  75. void die(char *);
  76. void get_ip_addr(struct in_addr*,char*);
  77. void get_hw_addr(char*,char*);

  78. int main (int argc,char** argv) {

  79.     char src_hw_addr[32];
  80.     char dst_hw_addr[32];
  81.     char src_ip[32];
  82.     char dst_ip[32];
  83.     char interface[32];
  84.     u_short type = 1;
  85.     char *arg;
  86.     u_short verbose = 0;
  87.     int i = 1;
  88.     u_short help = 0;

  89.     strcpy(src_hw_addr, "00:00:00:00:00:00");
  90.     strcpy(dst_hw_addr, "00:00:00:00:00:00");
  91.     strcpy(src_ip, "0.0.0.0");
  92.     strcpy(dst_ip, "0.0.0.0");
  93.     strcpy(interface, "eth0");

  94.     if (argc <= 1) help = 1;

  95.     while (arg = argv[i]) {
  96.         i++;

  97.         if (strcmp("-i", arg) == 0) {
  98.             strncpy(interface, argv[i++], 31);
  99.         } else if (strcmp("-p", arg) == 0) {
  100.             strncpy(src_ip, argv[i++], 31);
  101.         } else if (strcmp("-P", arg) == 0) {
  102.             strncpy(dst_ip, argv[i++], 31);
  103.         } else if (strcmp("-h", arg) == 0) {
  104.             strncpy(src_hw_addr, argv[i++], 31);
  105.         } else if (strcmp("-H", arg) == 0) {
  106.             strncpy(dst_hw_addr, argv[i++], 31);
  107.         } else if (strcmp("-v", arg) == 0) {
  108.             verbose = 1;
  109.         } else if (strcmp("-t", arg) == 0) {
  110.             arg = argv[i++];
  111.             if (strcmp("1", arg) == 0) type = 1;
  112.             else if (strcmp("2", arg) == 0) type = 2;
  113.             else if (strcmp("3", arg) == 0) type = 3;
  114.             else if (strcmp("4", arg) == 0) type = 4;
  115.             else if (strcmp("8", arg) == 0) type = 8;
  116.             else if (strcmp("9", arg) == 0) type = 9;
  117.         } else {
  118.             help = 1;
  119.         }
  120.     }

  121.     if (help) printf("%s", usage);

  122.     if (verbose) {
  123.         printf("Sending ARP Packet:\n");
  124.         printf("    Interface:                %s\n", interface);
  125.         printf("    Message type:             %d\n", type);
  126.         printf("    Sender hardware address:  %s\n", src_hw_addr);
  127.         printf("    Sender protocol address:  %s\n", src_ip);
  128.         printf("    Target hardware address:  %s\n", dst_hw_addr);
  129.         printf("    Target protocol address:  %s\n", dst_ip);
  130.     }

  131.     send_arp(src_ip, src_hw_addr, dst_ip, dst_hw_addr, interface, type);

  132.     exit (0);
  133. }

  134. void send_arp(char *src_ip, char *src_hw_addr, char *dst_ip, char *dst_hw_addr, char *interface, u_short type){

  135.     struct in_addr src_in_addr,dst_in_addr;
  136.     struct arp_packet pkt;
  137.     struct sockaddr sa;
  138.     int sock;

  139.     sock=socket(AF_INET,SOCK_PACKET,htons(ETH_P_RARP));
  140.     if(sock<0){
  141.         perror("socket");
  142.         exit(1);
  143.     }

  144.     pkt.frame_type = htons(ARP_FRAME_TYPE);
  145.     pkt.hw_type = htons(ETHER_HW_TYPE);
  146.     pkt.prot_type = htons(IP_PROTO_TYPE);
  147.     pkt.hw_addr_size = ETH_HW_ADDR_LEN;
  148.     pkt.prot_addr_size = IP_ADDR_LEN;
  149.     pkt.type=htons(type);

  150.     get_hw_addr(pkt.src_hw_addr, "ff:ff:ff:ff:ff:ff");
  151.     get_hw_addr(pkt.dst_hw_addr, "ff:ff:ff:ff:ff:ff");
  152.     get_hw_addr(pkt.sndr_hw_addr, src_hw_addr);
  153.     get_hw_addr(pkt.rcpt_hw_addr, dst_hw_addr);

  154.     get_ip_addr(&src_in_addr, src_ip);
  155.     get_ip_addr(&dst_in_addr, dst_ip);

  156.     memcpy(pkt.sndr_ip_addr,&src_in_addr,IP_ADDR_LEN);
  157.     memcpy(pkt.rcpt_ip_addr,&dst_in_addr,IP_ADDR_LEN);

  158.     bzero(pkt.padding,18);

  159.     strcpy(sa.sa_data, interface);

  160.     if(sendto(sock,&pkt,sizeof(pkt),0,&sa,sizeof(sa)) < 0){
  161.         perror("sendto");
  162.         exit(1);
  163.     }
  164.     exit(0);
  165. }

  166. void die(char* str){
  167.     fprintf(stderr,"%s\n",str);
  168.     exit(1);
  169. }

  170. void get_ip_addr(struct in_addr* in_addr,char* str){

  171.     struct hostent *hostp;

  172.     in_addr->;s_addr=inet_addr(str);
  173.     if(in_addr->;s_addr == -1){
  174.         if( (hostp = gethostbyname(str)))
  175.             bcopy(hostp->;h_addr,in_addr,hostp->;h_length);
  176.         else {
  177.             fprintf(stderr,"send_arp: unknown host %s\n",str);
  178.             exit(1);
  179.         }
  180.     }
  181. }

  182. void get_hw_addr(char* buf,char* str){

  183.     int i;
  184.     char c,val;
  185.     char hw_addr[64];

  186.     strcpy (hw_addr, str);

  187.     for(i=0;i<ETH_HW_ADDR_LEN;i++){
  188.         if( !(c = tolower(*str++))) {
  189.             char msg[64];
  190.             sprintf(msg, "Invalid hardware address: %s", hw_addr);
  191.             die(msg);
  192.         }
  193.         if(isdigit(c)) val = c-'0';
  194.         else if(c >;= 'a' && c <= 'f') val = c-'a'+10;
  195.         else {
  196.             char msg[64];
  197.             sprintf(msg, "Invalid hardware address: %s", hw_addr);
  198.             die(msg);
  199.         }

  200.         *buf = val << 4;
  201.         if( !(c = tolower(*str++))) die("Invalid hardware address");
  202.         if(isdigit(c)) val = c-'0';
  203.         else if(c >;= 'a' && c <= 'f') val = c-'a'+10;
  204.         else {
  205.             char msg[64];
  206.             sprintf(msg, "Invalid hardware address: %s", hw_addr);
  207.             die(msg);
  208.         }

  209.         *buf++ |= val;

  210.         if(*str == ':')str++;
  211.     }
  212. }



复制代码

论坛徽章:
6
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-03 17:33:522015元宵节徽章
日期:2015-03-06 15:50:39IT运维版块每日发帖之星
日期:2016-01-11 06:20:00IT运维版块每日发帖之星
日期:2016-03-19 06:20:0019周年集字徽章-19
日期:2019-09-06 18:56:11
3 [报告]
发表于 2003-03-10 13:25 |只看该作者

寻求 sendARP下载地址,请大哥们帮忙,谢谢啦

如何编译啊我没有在LINUX下编译软件写一下过程好吗

论坛徽章:
0
4 [报告]
发表于 2003-03-10 14:24 |只看该作者

寻求 sendARP下载地址,请大哥们帮忙,谢谢啦

先存到某个目录下,假设保存为arp.c,然后编译:
gcc -o arp arp.c
编译完成了会在当前目录下出先一个叫做arp的可执行文件
./arp执行

论坛徽章:
6
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-03 17:33:522015元宵节徽章
日期:2015-03-06 15:50:39IT运维版块每日发帖之星
日期:2016-01-11 06:20:00IT运维版块每日发帖之星
日期:2016-03-19 06:20:0019周年集字徽章-19
日期:2019-09-06 18:56:11
5 [报告]
发表于 2003-03-10 15:39 |只看该作者

寻求 sendARP下载地址,请大哥们帮忙,谢谢啦

谢谢

论坛徽章:
6
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-03 17:33:522015元宵节徽章
日期:2015-03-06 15:50:39IT运维版块每日发帖之星
日期:2016-01-11 06:20:00IT运维版块每日发帖之星
日期:2016-03-19 06:20:0019周年集字徽章-19
日期:2019-09-06 18:56:11
6 [报告]
发表于 2003-03-10 15:53 |只看该作者

寻求 sendARP下载地址,请大哥们帮忙,谢谢啦

我把你给的程序在windows下保存为arp.c在linux下不能编译.

论坛徽章:
0
7 [报告]
发表于 2003-03-10 20:06 |只看该作者

寻求 sendARP下载地址,请大哥们帮忙,谢谢啦

没有问题。存为arp.c的话,正确的编译方式为
gcc -o arp arp.c
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP