[Solved] Best Approach for Find All IPs in a subnet
-
Hello friends.
I could find IP & net mask of an interface. But I have no good idea to Find all possible IPs in the net mask!
Do you have any suggestion?Thanks a lot.
Ya Ali. -
Thanks be to GOD!
I found! Here`s the code
For example my IP is "192.168.1.51" & the subnetmask is "255.255.255.0".
The code shows all IPs in the subnet:@
QHostAddress MyAddress("192.168.1.51");
QPair<QHostAddress, int> subnetParser = QHostAddress::parseSubnet("192.168.1.51/255.255.255.0");
QHostAddress HA;quint32 DownMyAddressInt, UpMyAddressInt; DownMyAddressInt = MyAddress.toIPv4Address(); UpMyAddressInt = MyAddress.toIPv4Address() + 1; bool Finished = false; while(!Finished) { HA.setAddress(DownMyAddressInt); if(HA.isInSubnet(subnetParser)) { ui->MyComboBox->addItem(HA.toString()); DownMyAddressInt--; } else Finished = true; } Finished = false; while(!Finished) { HA.setAddress(UpMyAddressInt); if(HA.isInSubnet(subnetParser)) { ui->MyComboBox->addItem(HA.toString()); UpMyAddressInt++; } else Finished = true; }
@
The code is simple but works fine!