use nmap instead of arp-scan as it is more reliable
This commit is contained in:
parent
822f63861a
commit
d2cf8b90c0
@ -77,16 +77,13 @@ QVariant Device::stateValue(const QUuid &stateTypeId) const
|
|||||||
|
|
||||||
void Device::setStateValue(const QUuid &stateTypeId, const QVariant &value)
|
void Device::setStateValue(const QUuid &stateTypeId, const QVariant &value)
|
||||||
{
|
{
|
||||||
qDebug() << "setting state for id" << stateTypeId;
|
|
||||||
for (int i = 0; i < m_states.count(); ++i) {
|
for (int i = 0; i < m_states.count(); ++i) {
|
||||||
qDebug() << "got state id" << m_states.at(i).stateTypeId();
|
|
||||||
if (m_states.at(i).stateTypeId() == stateTypeId) {
|
if (m_states.at(i).stateTypeId() == stateTypeId) {
|
||||||
State newState(stateTypeId, m_id);
|
State newState(stateTypeId, m_id);
|
||||||
newState.setValue(value);
|
newState.setValue(value);
|
||||||
m_states[i] = newState;
|
m_states[i] = newState;
|
||||||
qDebug() << "set state for device" << value;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << "failed setting state" << value;
|
qWarning() << "failed setting state for" << m_name;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,7 +78,7 @@ void DevicePluginWifiDetector::hiveTimer()
|
|||||||
{
|
{
|
||||||
QProcess *p = new QProcess(this);
|
QProcess *p = new QProcess(this);
|
||||||
connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
|
connect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
|
||||||
p->start(QStringLiteral("arp-scan"), QStringList() << "--localnet" << "-I" << "eth2" );
|
p->start(QStringLiteral("sudo"), QStringList() << "nmap" << "-sP" << "10.10.10.0/24");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
@ -86,6 +86,12 @@ void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatu
|
|||||||
QProcess *p = static_cast<QProcess*>(sender());
|
QProcess *p = static_cast<QProcess*>(sender());
|
||||||
p->deleteLater();
|
p->deleteLater();
|
||||||
|
|
||||||
|
if (exitCode != 0 || exitStatus != QProcess::NormalExit) {
|
||||||
|
qWarning() << "error performing network scan:";
|
||||||
|
qWarning() << p->readAllStandardError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QList<Device*> watchedDevices = deviceManager()->findConfiguredDevices(supportedDevices().first().id());
|
QList<Device*> watchedDevices = deviceManager()->findConfiguredDevices(supportedDevices().first().id());
|
||||||
if (watchedDevices.isEmpty()) {
|
if (watchedDevices.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@ -94,16 +100,18 @@ void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatu
|
|||||||
QStringList foundDevices;
|
QStringList foundDevices;
|
||||||
while(p->canReadLine()) {
|
while(p->canReadLine()) {
|
||||||
QString result = QString::fromLatin1(p->readLine());
|
QString result = QString::fromLatin1(p->readLine());
|
||||||
QStringList lineParts = result.split('\t');
|
if (result.startsWith("MAC Address:")) {
|
||||||
if (lineParts.count() > 1) {
|
QStringList lineParts = result.split(' ');
|
||||||
QString addr = lineParts.at(1);
|
if (lineParts.count() > 3) {
|
||||||
foundDevices << addr;
|
QString addr = lineParts.at(2);
|
||||||
|
foundDevices << addr.toLower();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Device *device, watchedDevices) {
|
foreach (Device *device, watchedDevices) {
|
||||||
bool wasInRange = device->stateValue(inRangeStateTypeId).toBool();
|
bool wasInRange = device->stateValue(inRangeStateTypeId).toBool();
|
||||||
bool wasFound = foundDevices.contains(device->params().value("mac").toString());
|
bool wasFound = foundDevices.contains(device->params().value("mac").toString().toLower());
|
||||||
if (wasInRange != wasFound) {
|
if (wasInRange != wasFound) {
|
||||||
device->setStateValue(inRangeStateTypeId, wasFound);
|
device->setStateValue(inRangeStateTypeId, wasFound);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user