Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How do I determine if a particular interface is using DHCP?
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.
You’ll likely have to check your OS configuration for that.
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
JonB last edited by JonB
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.
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.
Can you show the code you are using ?
JonB last edited by
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.
graniteDev last edited by 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.
JonB last edited by
EnableDHCP. Always copy & paste from examples (unless the example is wrong)!
@JonB I'm going to go hide in shame now. Was reading the name wrong out of the registry....works fine.
@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.