Find all IPs in a subnet

廉价感情. 提交于 2019-12-24 19:33:46

问题


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



来源:https://stackoverflow.com/questions/12212300/find-all-ips-in-a-subnet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!