Commit 723a9690 by 郭峰

Merge branch 'feature-1007488' into 'release'

修改ping命令-07

See merge request !46
parents 6b97cdf9 6139d6d8
...@@ -80,11 +80,8 @@ public: ...@@ -80,11 +80,8 @@ public:
//确定当前网络接口 //确定当前网络接口
void determine_interface(char *interface); void determine_interface(char *interface);
QString GetLocalMac(const char *eth_inf); // 获取本机mac
QString GetLocalNetMask(const char *eth_inf); //获取本机mask
QString GetLocalGateWay();//获取本机gateway
QString GetLocalGateWay();//获取本机gateway
bool pingAddress(const QString &address) ; bool pingAddress(const QString &address) ;
......
...@@ -29,22 +29,18 @@ bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){ ...@@ -29,22 +29,18 @@ bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){
// 确定当前网络接口 // 确定当前网络接口
instace.determine_interface(interface); instace.determine_interface(interface);
// 获取网络信息
QString localMac= instace.GetLocalMac(interface); QString subnetMask;
QString subnetMask= instace.GetLocalNetMask(interface);
bool sub=vides_data::GetSubnetMask(subnetMask);
QString gateway= instace.GetLocalGateWay(); QString gateway= instace.GetLocalGateWay();
qInfo() <<QString("SN(%1): 获取本地MAC:%2,subnetMask:%3,gateway:%4").arg(device.sSn).arg(localMac)
.arg(subnetMask).arg(gateway);
if ( localMac.length()==0 && subnetMask.length()==0 && gateway.length()==0 ) { if ( !sub && gateway.length()==0 ) {
qInfo() <<QString("SN(%1): 获取本地MAC失败").arg(device.sSn); qInfo() <<QString("SN(%1): 获取本地MAC失败").arg(device.sSn);
return false ; return false ;
} }
QByteArray && byJson = localMac.toUtf8();
const char * mac= byJson.data();
QByteArray && byJsonIp = device.reachableIp.toUtf8(); QByteArray && byJsonIp = device.reachableIp.toUtf8();
const char * charIp= byJsonIp.data(); const char * charIp= byJsonIp.data();
...@@ -131,7 +127,7 @@ bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){ ...@@ -131,7 +127,7 @@ bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){
strcpy(devInfo.HostName, pDevice->HostName); strcpy(devInfo.HostName, pDevice->HostName);
devInfo.HttpPort = pDevice->HttpPort; devInfo.HttpPort = pDevice->HttpPort;
strcpy(devInfo.LocalMac, mac); //strcpy(devInfo.LocalMac, pDevice);
devInfo.MaxBps = pDevice->MaxBps; devInfo.MaxBps = pDevice->MaxBps;
devInfo.MaxConn = pDevice->MaxConn; devInfo.MaxConn = pDevice->MaxConn;
devInfo.MonMode = pDevice->MonMode; devInfo.MonMode = pDevice->MonMode;
......
...@@ -440,6 +440,29 @@ inline bool isInSameSubnet(const QString &ip1, const QString &ip2, const QString ...@@ -440,6 +440,29 @@ inline bool isInSameSubnet(const QString &ip1, const QString &ip2, const QString
// 比较结果 // 比较结果
return result1 == result2; return result1 == result2;
} }
// 获取子网掩码
inline bool GetSubnetMask(QString &subnetMask) {
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interface, interfaces) {
if (interface.flags().testFlag(QNetworkInterface::IsUp) &&
interface.flags().testFlag(QNetworkInterface::IsRunning) &&
!interface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
foreach (QNetworkAddressEntry entry, addressEntries) {
if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol) {
subnetMask = entry.netmask().toString();
return true; // 成功获取子网掩码
}
}
}
}
// 如果没有找到合适的接口或子网掩码
subnetMask = "Unknown";
return false;
}
inline bool pingAddress(const QString &address) { inline bool pingAddress(const QString &address) {
QProcess cmd; QProcess cmd;
......
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