//---------------------------------------------
//-----------------DHCP PACKET-----------------
//---------------------------------------------
dhcp_packet::dhcp_packet(QHostAddress ip, QHostAddress netmask, QNetworkInterface inter)
{
    this->op = 0x01;

    this->htype = 0x01;

    this->hlen = 0x06;

    this->hops = 0x00;

    this->xid[0] = 0x63;
    this->xid[1] = 0x9F;
    this->xid[2] = 0xC0;
    this->xid[3] = 0x4B;

    this->secs[0] = 0x00;
    this->secs[1] =0x00;

    this->flags[0] = 0x00;
    this->flags[1] = 0x00;

    this->ciaddr = ip.toIPv4Address();

    this->yiaddr = 0x00000000;

    this->siaddr = ip.toIPv4Address() & netmask.toIPv4Address();

    for (int i = 0; i < 4; i++)
        this->giaddr[i] = 0x00;


    qDebug() << inter.hardwareAddress();
    bool ok;
    this->chaddr[0] = QString::fromStdString(inter.hardwareAddress().toStdString().substr(0, 2)).toInt(&ok, 16);
    this->chaddr[1] = QString::fromStdString(inter.hardwareAddress().toStdString().substr(3, 2)).toInt(&ok, 16);
    this->chaddr[2] = QString::fromStdString(inter.hardwareAddress().toStdString().substr(6, 2)).toInt(&ok, 16);
    this->chaddr[3] = QString::fromStdString(inter.hardwareAddress().toStdString().substr(9, 2)).toInt(&ok, 16);
    this->chaddr[4] = QString::fromStdString(inter.hardwareAddress().toStdString().substr(12, 2)).toInt(&ok, 16);
    this->chaddr[5] = QString::fromStdString(inter.hardwareAddress().toStdString().substr(15, 2)).toInt(&ok, 16);
    for (int i = 0; i < 5; i++)
        qDebug() << chaddr[i];
    for (int i = 0; i < 10; i++)
        this->chaddr[i+6] = 0x00;

    for (int i = 0; i < 64; i++)
        this->sname[i] = 0x00;

    for (int i = 0; i < 128; i++)
        this->file[i] = 0x00;

    //DHCP protocols
    options.append(0x63);
    options.append(0x82);
    options.append(0x53);
    options.append(0x63);
}
Exemplo n.º 2
0
//someone selected another interface
void ApplicationWindow::interfaceBoxIndexChanged(int boxIndex)
{
    //get the right index data
    int interfaceIndex=interfaceBox->itemData(boxIndex).toInt();
    QNetworkInterface tmpInterface = QNetworkInterface::interfaceFromIndex (interfaceIndex);

    macLine->setText(tmpInterface.hardwareAddress());
   // indexLine->setText(QString("%1").arg(interfaceIndex));

    QList<QNetworkAddressEntry> interfaceAdresses;
    interfaceAdresses=tmpInterface.addressEntries();

    if (interfaceAdresses.size()>0)
    {
        ipLine->setText(interfaceAdresses[0].ip().toString());
        maskLine->setText(interfaceAdresses[0].netmask().toString());
    }
    else
    {
        ipLine->setText("");
        maskLine->setText("");
    }
        writeLog(createHeaderText());

}
Exemplo n.º 3
0
QString DeviceManager::getDeviceMac()
{
    QNetworkInterface *qni;
    qni = new QNetworkInterface();
    *qni = qni->interfaceFromName(QString("%1").arg("wlan0"));
    return qni->hardwareAddress();
}
Exemplo n.º 4
0
 //Source : http://stackoverflow.com/a/7616111
 foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces())
     {
         // Return only the first non-loopback MAC Address
         if (!(netInterface.flags() & QNetworkInterface::IsLoopBack)){
             macAddress = netInterface.hardwareAddress();
             break;
         }
     }
Exemplo n.º 5
0
OrderSave::OrderSave(QObject *parent) :
    QObject(parent)
{
      QNetworkInterface *qni;
      qni = new QNetworkInterface();
      *qni = qni->interfaceFromName(QString("%1").arg("eth0"));
      mac = qni->hardwareAddress();
      //»ñÈ¡MACµØÖ·
}
Exemplo n.º 6
0
void PJobRunnerNetworkScanner::scan(const QNetworkInterface& interface){
    foreach(const QNetworkAddressEntry& address_entry, interface.addressEntries()){
        if(m_want_stop) break;
        quint32 netmask = address_entry.netmask().toIPv4Address();
        quint32 local_ip = address_entry.ip().toIPv4Address();
        quint32 address_to_try = (local_ip & netmask) + 1;
        //quint32 inv_netmask = ~netmask;

        if(interface.humanReadableName() == "lo"){
            std::cout << "Skipping interface \"lo\"." << std::endl;
            continue;
        }

        if(!interface.isValid()){
            std::cout << "Skipping interface \"" << interface.humanReadableName().toStdString() << "\"." << std::endl;
            continue;
        }

        if(address_entry.ip().protocol() != QAbstractSocket::IPv4Protocol){
            std::cout << "Skipping non-IPv4 interface." << std::endl;
            continue;
        }

        if(address_entry.ip() == QHostAddress::LocalHost){
            std::cout << "Skipping loopback interface." << std::endl;
            continue;
        }

        if(address_entry.ip().isNull()){
            continue;
        }

        std::cout << "Probing interface " << interface.humanReadableName().toStdString() << std::endl;
        std::cout << "Local address is " << interface.hardwareAddress().toStdString() << std::endl;
        std::cout << "Netmask: " << address_entry.netmask().toString().toStdString() << std::endl;
        std::cout << "Searching local network..." << std::endl;
        while((address_to_try & netmask) == (local_ip & netmask)){
            if(m_want_stop) break;
            std::cout << "\r" << QHostAddress(address_to_try).toString().toStdString();
            std::cout.flush();
            emit probing_host(QHostAddress(address_to_try));
            PJobRunnerSessionWrapper* session = new PJobRunnerSessionWrapper(QHostAddress(address_to_try), 50);
            if(session->is_valid()) found(session);
            else delete session;
            address_to_try++;
        }
    }
    emit finished_scanning();
    m_want_stop = false;
}
Exemplo n.º 7
0
DeviceList::DeviceList() :
    QObject(NULL), _scanner() {
    qRegisterMetaType<DeviceInfo>("DeviceInfo");
    _started = false;
    _currentDev = NULL;

    QNetworkInterface iface = NetUtils::getPreferedInterface();
    DeviceInfo computer;
    computer.mac = NetUtils::strToMac(iface.hardwareAddress());
    computer.ip = NetUtils::getIp(iface).toString();
    computer.name = "Cet Ordinateur";
    computer.status = Device::CurrentComputer;
    computer.type = Device::ChapiServer;
    _currentDev = generateDevice(computer, true);
    _devices.insert(computer.mac, _currentDev);
}
Exemplo n.º 8
0
void squeezeLiteGui::getplayerMACAddress(void)
{
    DEBUGF("");
    MacAddress = QByteArray( "00:00:00:00:00:04" );

    QList<QNetworkInterface> netList = QNetworkInterface::allInterfaces();
    QListIterator<QNetworkInterface> i( netList );

    QNetworkInterface t;

    while( i.hasNext() ) {  // note: this grabs the first functional, non-loopback address there is.  It may not the be interface on which you really connect to the slimserver
        t = i.next();
        if( !t.flags().testFlag( QNetworkInterface::IsLoopBack ) &&
                t.flags().testFlag( QNetworkInterface::IsUp ) &&
                t.flags().testFlag( QNetworkInterface::IsRunning ) ) {
            MacAddress = t.hardwareAddress().toLatin1().toLower();
            if(!MacAddress.contains("%3A")) // not escape encoded
                encodedMacAddress = QString(MacAddress).toLatin1().toPercentEncoding();
            return;
        }
    }
}
Exemplo n.º 9
0
void QGenericEngine::doRequestUpdate()
{
#ifndef QT_NO_NETWORKINTERFACE
    QMutexLocker locker(&mutex);

    // Immediately after connecting with a wireless access point
    // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a
    // second time results in a non-empty list. If we loose interfaces we will end up removing
    // network configurations which will break current sessions.
    QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
    if (interfaces.isEmpty())
        interfaces = QNetworkInterface::allInterfaces();

    QStringList previous = accessPointConfigurations.keys();

    // create configuration for each interface
    while (!interfaces.isEmpty()) {
        QNetworkInterface interface = interfaces.takeFirst();

        if (!interface.isValid())
            continue;

        // ignore loopback interface
        if (interface.flags() & QNetworkInterface::IsLoopBack)
            continue;

        // ignore WLAN interface handled in separate engine
        if (qGetInterfaceType(interface.name()) == QNetworkConfiguration::BearerWLAN)
            continue;

        uint identifier;
        if (interface.index())
            identifier = qHash(QLatin1String("generic:") + QString::number(interface.index()));
        else
            identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress());

        const QString id = QString::number(identifier);

        previous.removeAll(id);

        QString name = interface.humanReadableName();
        if (name.isEmpty())
            name = interface.name();

        QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined;
        if((interface.flags() & QNetworkInterface::IsUp) && !interface.addressEntries().isEmpty())
            state |= QNetworkConfiguration::Active;

        if (accessPointConfigurations.contains(id)) {
            QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);

            bool changed = false;

            ptr->mutex.lock();

            if (!ptr->isValid) {
                ptr->isValid = true;
                changed = true;
            }

            if (ptr->name != name) {
                ptr->name = name;
                changed = true;
            }

            if (ptr->id != id) {
                ptr->id = id;
                changed = true;
            }

            if (ptr->state != state) {
                ptr->state = state;
                changed = true;
            }

            ptr->mutex.unlock();

            if (changed) {
                locker.unlock();
                emit configurationChanged(ptr);
                locker.relock();
            }
        } else {
            QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);

            ptr->name = name;
            ptr->isValid = true;
            ptr->id = id;
            ptr->state = state;
            ptr->type = QNetworkConfiguration::InternetAccessPoint;
            ptr->bearerType = qGetInterfaceType(interface.name());

            accessPointConfigurations.insert(id, ptr);
            configurationInterface.insert(id, interface.name());

            locker.unlock();
            emit configurationAdded(ptr);
            locker.relock();
        }
    }

    while (!previous.isEmpty()) {
        QNetworkConfigurationPrivatePointer ptr =
            accessPointConfigurations.take(previous.takeFirst());

        configurationInterface.remove(ptr->id);

        locker.unlock();
        emit configurationRemoved(ptr);
        locker.relock();
    }

    locker.unlock();
#endif

    emit updateCompleted();
}
	foreach( QNetworkInterface netIf, QNetworkInterface::allInterfaces( ) ) {
		if( !( netIf.flags( ) & QNetworkInterface::IsLoopBack ) ) {
			return netIf.hardwareAddress( );
		}
	}