Find all IPs in a subnet

2019-09-12 11:33发布

问题:

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.

回答1:

i found a solution :

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



标签: c++ ip