From a009462117d4a9cd4221e83a99b3f45dd0c39fb8 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Fri, 27 May 2016 11:01:16 +0200 Subject: [PATCH] Send an ARP request to every IP on the subnet --- arp_scan.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arp_scan.c b/arp_scan.c index 87acd8c..c4b2c8f 100644 --- a/arp_scan.c +++ b/arp_scan.c @@ -137,8 +137,32 @@ int main(int argc, char **argv) #ifdef DEBUG printf("[OK] Local netmask: %s\n", netmask_string); #endif - + + /* ====================================================================== */ + + /* Using the local IP address and netmask, we can loop on every IP + address on the subnet, and send to every one an ARP request. */ + + /* This counter will loop through every available IP address on the + current subnet */ + unsigned long ip_counter = ntohl(ipaddr->sin_addr.s_addr) & ntohl(netmask->sin_addr.s_addr); + /* The maximum address on the subnet */ + unsigned long ip_max = ip_counter + (~ntohl(netmask->sin_addr.s_addr)); + + while (ip_counter < ip_max) { + char ip_string[16]; + struct in_addr target_ip; + target_ip.s_addr = htonl(ip_counter); + if (!inet_ntop(AF_INET, &target_ip.s_addr, ip_string, sizeof(ip_string))) { + perror("[FAIL] inet_ntop()"); + exit(EXIT_FAILURE); + } + printf("[%s]\n", ip_string); + send_arp_request(sockfd, ifindex, ipaddr, macaddr, target_ip); + + ++ip_counter; + } }