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. How do I determine if a particular interface is using DHCP?
Forum Updated to NodeBB v4.3 + New Features

How do I determine if a particular interface is using DHCP?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 1.9k 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.
  • G Offline
    G Offline
    graniteDev
    wrote on last edited by
    #1

    I know this isn't a Qt only question, but never the less, I'm using Qt and I need to determine if a particular interface is either using a static IP or DHCP.

    I already know how to use Qt to determine the IP address and netmask of interfaces, so I'm not asking for that help, but of how to determine if DHCP is being used on a particular interface.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You’ll likely have to check your OS configuration for that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • G Offline
        G Offline
        graniteDev
        wrote on last edited by
        #3

        Yes...I know this, I just can't find a way to do this on windows. ipconfig and half a dozen other commands will happily tell you in a human readable way but I've not found a programmatic way of determining this information

        JonBJ 1 Reply Last reply
        0
        • G graniteDev

          Yes...I know this, I just can't find a way to do this on windows. ipconfig and half a dozen other commands will happily tell you in a human readable way but I've not found a programmatic way of determining this information

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @graniteDev
          For Windows only, code is here: https://stackoverflow.com/a/12732644/489865 , and explanation https://support.microsoft.com/en-gb/help/314053/tcp-ip-and-nbt-configuration-parameters-for-windows-xp
          It's just a registry lookup.

          1 Reply Last reply
          3
          • G Offline
            G Offline
            graniteDev
            wrote on last edited by
            #5

            So this caused a new problem, how do I read a REG_DWORD with a hex value from the registry with QSettings?

            Right now it's just saying the value is invalid, so it gives me a 0 instead of providing me a 1, which the hex number is.

            JonBJ 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you show the code you are using ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • G graniteDev

                So this caused a new problem, how do I read a REG_DWORD with a hex value from the registry with QSettings?

                Right now it's just saying the value is invalid, so it gives me a 0 instead of providing me a 1, which the hex number is.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @graniteDev
                REG_DWORDs aren't "hex values", they are numbers (though e.g. RegEdit shows them as hex values).
                Please show the actual code you're using.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  graniteDev
                  wrote on last edited by graniteDev
                  #8

                  Sure, so essentially what I'm doing is I know the guid of the device I want to query from a previous query on the registery, that's the ifaceGuid variable.

                  bool isDHCP = false;
                  QString ifaceLoc = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces" + ifaceGuid;
                      QSettings iface(ifaceLoc, QSettings::NativeFormat);
                      int tmp = iface.value("EnabledDHCP").toInt();
                      isDHCP = tmp;
                  

                  This was returning false, when I'm looking at the value in the registry and it's a 1, so I throw a qDebug() in there and it returned "0" which makes no sense because it's most definitely a 1.

                  Now just for a sanity check I also grabbed other values out of that registry location that convert to strings, and I am query the right location and can get other REG_SZ values from this location so I know the code is working and grabbing values, so it's not just erroring out and providing a default "0". But I don't understand why I can't get the specific REG_DWORD value that I want.

                  In the registry EnabledDHCP has a value of 0x00000001 (1)

                  Edit: I forgot to mention that without converting the QVariant to an int, the value qDebug() provides is "invalid" so some how the value in EnabledDHCP is getting lost in translation and is invalid for a QVariant.

                  JonBJ 1 Reply Last reply
                  0
                  • G graniteDev

                    Sure, so essentially what I'm doing is I know the guid of the device I want to query from a previous query on the registery, that's the ifaceGuid variable.

                    bool isDHCP = false;
                    QString ifaceLoc = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces" + ifaceGuid;
                        QSettings iface(ifaceLoc, QSettings::NativeFormat);
                        int tmp = iface.value("EnabledDHCP").toInt();
                        isDHCP = tmp;
                    

                    This was returning false, when I'm looking at the value in the registry and it's a 1, so I throw a qDebug() in there and it returned "0" which makes no sense because it's most definitely a 1.

                    Now just for a sanity check I also grabbed other values out of that registry location that convert to strings, and I am query the right location and can get other REG_SZ values from this location so I know the code is working and grabbing values, so it's not just erroring out and providing a default "0". But I don't understand why I can't get the specific REG_DWORD value that I want.

                    In the registry EnabledDHCP has a value of 0x00000001 (1)

                    Edit: I forgot to mention that without converting the QVariant to an int, the value qDebug() provides is "invalid" so some how the value in EnabledDHCP is getting lost in translation and is invalid for a QVariant.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @graniteDev said in How do I determine if a particular interface is using DHCP?:

                    EnabledDHCP

                    It's spelt EnableDHCP. Always copy & paste from examples (unless the example is wrong)!

                    G 1 Reply Last reply
                    2
                    • JonBJ JonB

                      @graniteDev said in How do I determine if a particular interface is using DHCP?:

                      EnabledDHCP

                      It's spelt EnableDHCP. Always copy & paste from examples (unless the example is wrong)!

                      G Offline
                      G Offline
                      graniteDev
                      wrote on last edited by
                      #10

                      @JonB I'm going to go hide in shame now. Was reading the name wrong out of the registry....works fine.

                      aha_1980A 1 Reply Last reply
                      0
                      • G graniteDev

                        @JonB I'm going to go hide in shame now. Was reading the name wrong out of the registry....works fine.

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @graniteDev please don't delete a topic that was sucessfully solved.

                        others may profit from the solution too, and its unfair to destroy the help others gave you.

                        thanks

                        Qt has to stay free or it will die.

                        1 Reply Last reply
                        3

                        • Login

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