Commit 6139d6d8 by “liusq”

修改ping命令-07

parent d0fe659b
......@@ -80,11 +80,8 @@ public:
//确定当前网络接口
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) ;
......
......@@ -29,21 +29,17 @@ bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){
// 确定当前网络接口
instace.determine_interface(interface);
// 获取网络信息
QString localMac= instace.GetLocalMac(interface);
QString subnetMask= instace.GetLocalNetMask(interface);
QString subnetMask;
bool sub=vides_data::GetSubnetMask(subnetMask);
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);
return false ;
}
QByteArray && byJson = localMac.toUtf8();
const char * mac= byJson.data();
QByteArray && byJsonIp = device.reachableIp.toUtf8();
const char * charIp= byJsonIp.data();
......@@ -131,7 +127,7 @@ bool NonConnectedCameraHandle::changeCameraIp(vides_data::localDevice &device){
strcpy(devInfo.HostName, pDevice->HostName);
devInfo.HttpPort = pDevice->HttpPort;
strcpy(devInfo.LocalMac, mac);
//strcpy(devInfo.LocalMac, pDevice);
devInfo.MaxBps = pDevice->MaxBps;
devInfo.MaxConn = pDevice->MaxConn;
devInfo.MonMode = pDevice->MonMode;
......
......@@ -440,6 +440,29 @@ inline bool isInSameSubnet(const QString &ip1, const QString &ip2, const QString
// 比较结果
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) {
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