WOL is Wake Up On Lan
Used for wake-up WOL supported Device on the internal Lan
Works Good
Envir: Qt free 4.4.3 for Win + VS2005
Demo Soft
WOL.zip (40 K) 下载次数:3 Attention: App doesnot include related DLLs, Pls add core/gui/network by yourself
About Me:
Yooi@msn.com always wlc
Main functions copy here:
*************************************************
void WolDialog::calcMagicPack()
{
address = macLine->text();
if(address.isEmpty())
{
emit state(4);
return;
}
//get real address
address.remove(QRegExp("[^0-9a-fA-F]"));
if( false == verifyMacAddress(address) )
{
emit state(0);
return;
}
saveChange = true;
/*!
"FFFFFFFFFFFF"+16 duplicate MAC
*/
//generate Magic Packet
// type 1
magicPack = new QByteArray;
magicPack->fill((unsigned char)0xff, 6);
for(int i = 0; i < 16; i++)
{
magicPack->append( QByteArray::fromHex(address.toAscii()) );
}
emit state(1);
QTimer::singleShot(100, this, SLOT(sendOutWolPack()));
}
bool WolDialog::verifyMacAddress(const QString& addr)const
{
qDebug() << addr;
if(addr.length() != 12)
{
return false;
}
return true;
}
void WolDialog::sendOutWolPack()
{
qint64 ref = socket->writeDatagram(magicPack->data(), magicPack->size(),
QHostAddress::Broadcast, 45454);
qDebug() << magicPack->size() << magicPack->constData();
if(ref == -1)
{
emit state(6);
}
else
{
emit state(5);
}
}
void WolDialog::updateState(int type)
{
QString msg;
switch(type)
{
case 0: msg = "Incorrect MAC ADDRESS"; break;
case 1: msg = "Sending out BroadCast"; break;
case 3: msg = "Unknown Error"; break;
case 4: msg = "ADDRESS is Null, Pls fill"; break;
case 5: msg = "Complete"; break;
case 6: msg = "Fail to send out!"; break;
}
stateLabel->setText(msg);
}
[ 此帖被yooi在2009-03-31 12:14重新编辑 ]