qt5多线程扫描器帮助!!!!!

大家好!我是新手,提一个问题!如何实现控制台的多线程端口扫描器。
我已经完成了单线程扫描器
//头文件
#ifndef SCAN_H
#define SCAN_H
#include
#include
#include
#include
void scan( QString ad,int sp,int ep)
{
//连接并验证端口是否打开
QTcpSocket connct;
int temp=sp;
QList list;//保存扫描结果
for(;temp<=ep;temp++)
{

connct.connectToHost(ad,temp);

if(connct.waitForConnected(100))
    {
     list.append(temp);
     qDebug()<<"address--"<<ad<<":"<<temp<<"open!"<<endl;
}else{
    qDebug()<<"address--"<<ad<<":"<<temp<<"close!"<<endl;

}
connct.abort();//断开连接

}
qDebug()<<“address–”<<ad<<":"<<“Finish!”<<endl;
qDebug()<<“open-port:”<<list<<endl;
}
#endif // SCAN_H
#include
#include
#include
#include
#include
#include
#include “scan.h”
//主程序
int main(int argc,char* argv[ ])
{
QCoreApplication a(argc,argv);
//为了QT使用c++标准输入输出
QTextStream cin(stdin, QIODevice::ReadOnly);
QTextStream cout(stdout, QIODevice::WriteOnly);
//地址和端口号
int sport,eport,num;
QString address,name;
QHostInfo adsname;
cout<<"#################################################"<<endl;
cout<<"#################################################"<<endl;
cout<<"######PortScanner###Ver 1.0######################"<<endl;
cout<<"########################Power by JudeMoses#######"<<endl;
cout<<"#################################################"<<endl;
cout<<"#################################################"<<endl;
while(1){
cout<<"#please input a number (1:IP 2:website name)#####"<<endl;
cin>>num;
switch (num)
{
case 1:
cout<<“IP?”<<endl;
cin>>address;
cout<<“IP–”<<address<<endl;
cout<<“Start Port?”<<endl;
cin>>sport;
cout<<“End Port?”<<endl;
cin>>eport;
cout<<“Start-port–”<<sport<<endl;
cout<<“End—port–”<<eport<<endl;
scan (address,sport,eport);
break;

case 2:

    cout<<"website name?"<<endl;
    cin>>name;

    adsname = QHostInfo::fromName(name);
    address=adsname.addresses().first().toString();
    cout<<"IP--"<<address<<endl;
    cout<<"Start Port?"<<endl;
    cin>>sport;
    cout<<"End Port?"<<endl;
    cin>>eport;
    cout<<"Start-port--"<<sport<<endl;
    cout<<"End---port--"<<eport<<endl;
    scan (address,sport,eport);
    break;

 default:
    cout<<"#######WARNING###################################"<<endl;
    cout<<"#######WARNING###################################"<<endl;
    cout<<"#######WARNING###################################"<<endl;
  break;
}

}
a.exec();

}

猜你喜欢

转载自blog.csdn.net/judemoses/article/details/85317668