0

I am developing a part of code using C++ for our project, my code must return a list of all available IPs in a subnet, so I have this scenario:

  1. Get my subnet.

  2. Test every IP in subnet using a for loop, e.g.:

    for (int i = 0; i < 254; i++)
    {
        testip(X, X, X, i);
        /* if IP is valid */
        vectoriplist.push_back(X, X, X, i);
    }
    

For find subnet I think I will use IPnetwork utility, but I still have another problem and it's how I can test if the IP is valid on the subnet. I try to use boost.asio, but I cannot find anything.

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
user1344201
  • 217
  • 1
  • 5
  • 13
  • It depends on what you call a valid IP address, is it an address whose corresponding piece of hardware responds to ping request? Then you can try with a simple SYN / ACK tcp ping – Jaffa Aug 31 '12 at 09:16
  • Assuming the network is link-local, i.e. visible through your link, you can use the fact that every IPv4-subnet has a broadcast address. For IPv6 a simple ping to ff02::1 (all-nodes-address) will do the trick. – hroptatyr Aug 31 '12 at 09:31
  • You could use fping to find valid nodes in a subnet. http://www.cyberciti.biz/tips/linux-unix-profiling-network-connectivity-with-fping.html – Arvind Aug 31 '12 at 09:35
  • Note though that some hosts may choose to ignore ICMP ECHO requests (aka ping) and TCP SYNs to arbitrary ports, depending on their firewall settings. ARP may be more reliable, though it's link-local too. – atzz Aug 31 '12 at 09:37
  • thank you , but is there any code example c++ – user1344201 Aug 31 '12 at 10:17

1 Answers1

0

i found a solution :

i use coonect() and getpeername() functions in for loop . to get all valid ip addresses in a subnet

user1344201
  • 217
  • 1
  • 5
  • 13