Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Best Approach for Find All IPs in a subnet
Forum Updated to NodeBB v4.3 + New Features

[Solved] Best Approach for Find All IPs in a subnet

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MohammadReza
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MohammadReza
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved