Commit 4e92ddc7 by “liusq”

修改一建配置Ip的问题

parent e93312cf
......@@ -49,6 +49,8 @@ bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){
if (nCount <= 0) {
qInfo() << QString("SN(%1): 有线搜索不到设备").arg(device.sSn);
//搜索不到设备也当不在,当不在同一网段
device.isMask=false;
return false;
}
......@@ -92,11 +94,18 @@ bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){
.arg(pDevice->HostIP.c[1])
.arg(pDevice->HostIP.c[2])
.arg(pDevice->HostIP.c[3]);
if(vides_data::isInSameSubnet(device.reachableIp,new_ip,subnetMask)){
QString new_Submask=QString("%1.%2.%3.%4")
.arg(pDevice->Submask.c[0])
.arg(pDevice->Submask.c[1])
.arg(pDevice->Submask.c[2])
.arg(pDevice->Submask.c[3]);
if(vides_data::isInSameSubnet(device.reachableIp,new_ip,new_Submask)){
device.isMask=true;
}else{
device.isMask=false;
}
device.nDevPort=pDevice->TCPPort;
XSDK_EncryptPassword("", newEncryptPsw, 512);
......@@ -200,8 +209,6 @@ void NonConnectedCameraHandle::printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_W
int NonConnectedCameraHandle::sdkDevLoginSyn(QString sDevId, int nDevPort,
QString sUserName, QString sPassword, int nTimeout) {
SXSDKLoginParam *loginParam=new SXSDKLoginParam();
ScopeSemaphoreExit guard([&loginParam]() {
Common & instace= Common::getInstance();
MainWindow::sp_this->setIsResetting(false);
......
......@@ -438,8 +438,6 @@ inline bool isInSameSubnet(const QString &ip1, const QString &ip2, const QString
// 比较结果
return result1 == result2;
}
// 获取本地 MAC 地址、子网掩码和网关IP
inline bool GetNetworkInfoByQNetworkInterface(QString &mac, QString &subnetMask, QString &gateway) {
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interface, interfaces) {
......@@ -452,13 +450,37 @@ inline bool GetNetworkInfoByQNetworkInterface(QString &mac, QString &subnetMask,
foreach (QNetworkAddressEntry entry, addressEntries) {
if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol) {
subnetMask = entry.netmask().toString();
gateway = entry.broadcast().toString(); // 这里假设网关是广播地址
// 获取网关地址
QProcess process;
process.start("ip", QStringList() << "route");
if (!process.waitForStarted()) {
qInfo() << "Failed to start 'ip route' process.";
continue;
}
if (!process.waitForFinished()) {
process.kill();
qInfo() << "Process 'ip route' timed out.";
continue;
}
QString output = process.readAllStandardOutput();
QStringList lines = output.split('\n');
foreach (QString line, lines) {
if (line.startsWith("default via")) {
QStringList parts = line.split(QRegExp("\\s+"));
if (parts.size() >= 3) {
gateway = parts[2];
return true;
}
}
}
}
return false; // Return false if no suitable interface is found
}
}
}
return false; // Return false if no suitable interface is found or gateway not found
}
inline bool pingAddress(const QString &address) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment