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)
|
||||
{
|
||||
qDebug() << "setting state for id" << stateTypeId;
|
||||
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) {
|
||||
State newState(stateTypeId, m_id);
|
||||
newState.setValue(value);
|
||||
m_states[i] = newState;
|
||||
qDebug() << "set state for device" << value;
|
||||
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);
|
||||
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)
|
||||
@ -86,6 +86,12 @@ void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatu
|
||||
QProcess *p = static_cast<QProcess*>(sender());
|
||||
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());
|
||||
if (watchedDevices.isEmpty()) {
|
||||
return;
|
||||
@ -94,16 +100,18 @@ void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatu
|
||||
QStringList foundDevices;
|
||||
while(p->canReadLine()) {
|
||||
QString result = QString::fromLatin1(p->readLine());
|
||||
QStringList lineParts = result.split('\t');
|
||||
if (lineParts.count() > 1) {
|
||||
QString addr = lineParts.at(1);
|
||||
foundDevices << addr;
|
||||
if (result.startsWith("MAC Address:")) {
|
||||
QStringList lineParts = result.split(' ');
|
||||
if (lineParts.count() > 3) {
|
||||
QString addr = lineParts.at(2);
|
||||
foundDevices << addr.toLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Device *device, watchedDevices) {
|
||||
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) {
|
||||
device->setStateValue(inRangeStateTypeId, wasFound);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user