void DNSUpdater::ipRequestFinished(QNetworkReply *reply) { qDebug() << Q_FUNC_INFO; if (reply->error()) { // Error qWarning() << Q_FUNC_INFO << "Error:" << reply->errorString(); } else { // Parse response QRegExp ipregex("Current IP Address:\\s+([^<]+)</body>"); QString ret = reply->readAll(); if (ipregex.indexIn(ret) >= 0) { QString ip_str = ipregex.cap(1); qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ip_str; QHostAddress new_ip(ip_str); if (!new_ip.isNull()) { if (m_lastIP != new_ip) { qDebug() << Q_FUNC_INFO << "The IP address changed, report the change to DynDNS..."; qDebug() << m_lastIP.toString() << "->" << new_ip.toString(); m_lastIP = new_ip; updateDNSService(); } } else { qWarning() << Q_FUNC_INFO << "Failed to construct a QHostAddress from the IP string"; } } else { qWarning() << Q_FUNC_INFO << "Regular expression failed ot capture the IP address"; } } // Clean up reply->deleteLater(); sender()->deleteLater(); }
int main(int argc, char *argv[]) { char ip[16]; strcpy(ip, "255.2XX.XX.X1X"); printf("%s\n", ipregex(ip)); return 0; }