An ARP reply program that was written a long time ago can sometimes be used at critical times. Save it. Once, the IP address of your server does not know which group you want to compete for. As a result, the network cannot be accessed, and the network administrator cannot find the server. There is really no way, just use this program to regain their IP address. Note that both the IP address and MAC address are false.
- # Include <stdio. h>
- # Include <stdlib. h>
- # Include <net/Ethernet. h>
- # Include <netinet/if_ether.h>
- # Include <netinet/in. h>
- # Include <sys/socket. h>
- # Define src_ip "238.221.236.83"
- # Define target_ip "238.221.236.119"
- Short src_mac [] = {0x00,0x03, 0x1a, 0x01,0x00,0x00 };
- Short target_mac [] = {0 x, 0 x, 0x25, 0x9d, 0xc1, 0xf0 };
- Void send_arp_reply (void );
- Int main (INT argc, char * ARGs [])
- {
- While (1)
- {
- Send_arp_reply ();
- Sleep (30 );
- }
- Return 0;
- }
- Void send_arp_reply (void)
- {
- Struct ether_header * eth_hdr;
- Struct ether_arp * ARP;
- Char datasync [60];
- Eth_hdr = (struct ether_header *) datasync;
- Memset (dataphin, 0, sizeof (dataphin ));
- // Set the Ethernet header
- Eth_hdr-> ether_dhost [0] = target_mac [0];
- Eth_hdr-> ether_dhost [1] = target_mac [1];
- Eth_hdr-> ether_dhost [2] = target_mac [2];
- Eth_hdr-> ether_dhost [3] = target_mac [3];
- Eth_hdr-> ether_dhost [4] = target_mac [4];
- Eth_hdr-> ether_dhost [5] = target_mac [5];
- Eth_hdr-> ether_shost [0] = src_mac [0];
- Eth_hdr-> ether_shost [1] = src_mac [1];
- Eth_hdr-> ether_shost [2] = src_mac [2];
- Eth_hdr-> ether_shost [3] = src_mac [3];
- Eth_hdr-> ether_shost [4] = src_mac [4];
- Eth_hdr-> ether_shost [5] = src_mac [5];
- Eth_hdr-> ether_type = htons (ethertype_arp );
- // Set the ARP Header
- ARP = (struct ARP *) (datasync + sizeof (struct ether_header ));
- ARP-> arp_hrd = htons (arphrd_ether );
- ARP-> arp_pro = htons (ethertype_ip );
- ARP-> arp_hln = 6;
- ARP-> arp_pln = 4;
- ARP-> arp_op = htons (2 );
- // ARP body
- // Sender MAC and IP
- Memcpy (void *) ARP-> arp_sha, (void *) eth_hdr-> ether_shost, 6 );
- Struct in_addr inadd_sender;
- Inet_aton (src_ip, & inadd_sender );
- Memcpy (void *) ARP-> arp_spa, (void *) & inadd_sender, 4 );
- // Target Mac and IP
- Memcpy (void *) ARP-> arp_tha, (void *) eth_hdr-> ether_dhost, 6 );
- Struct in_addr inadd_target;
- Inet_aton (target_ip, & inadd_target );
- Memcpy (void *) ARP-> arp_tpa, (void *) & inadd_target, 4 );
- // Establish socket
- Int FD = socket (af_inet, sock_packet, htons (eth_p_arp ));
- If (FD <0)
- {
- Perror ("socket ");
- Exit (-1 );
- }
- Struct sockaddr SA;
- Strcpy (SA. sa_data, "eth0 ");
- Sendto (FD, datax, sizeof (datax), 0, & SA, sizeof (SA ));
- Close (FD );
- Return;
- }
For specific message formats, see <TCP/IP details>