-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListThread.cpp
More file actions
executable file
·108 lines (69 loc) · 2.64 KB
/
Copy pathListThread.cpp
File metadata and controls
executable file
·108 lines (69 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Created by gaochong on 17-11-28.
//
#include "ListThread.h"
#include "LanIPListView.h"
#include "QCTools.h"
#include "GCSocketPortTest.h"
#include <QDebug>
ListThread::ListThread( TLanNetList* tLanNetList, int srCount ,int outTime ,int fPort,int fPortType , QObject *parent ):QThread(parent) {
this->tLanNetList = (TLanNetList*)malloc( sizeof( TLanNetList ) );
memcpy( this->tLanNetList ,tLanNetList ,sizeof( TLanNetList ) );
this->srCount = srCount;
this->outTime = outTime;
this->fPort = fPort;
this->fPortType = fPortType;
}
ListThread::~ListThread() {
//free( tLanNetList );
//delete tLanNetList;
}
void ListThread::run() {
testip = new GCIP;
GCSocketPortTest *testSocket = new GCSocketPortTest;
/** 地址段总数
* 开始 IP -- 结束 IP
* */
int count = testip->IP2Count( tLanNetList->SIP , tLanNetList->DIP );
/** 目标 IP */
char nip[20];
memset( nip, 0, 20);
strcpy( nip, tLanNetList->SIP );
for (int i = 0; i <= count; i++) {
LanTableRecord *ltRecord = new LanTableRecord;
GCArp *testarp = new GCArp( this->srCount , this->outTime );
const char *mac = testarp->GetRemoteIPMAC( tLanNetList->Local ,tLanNetList->LocalIP ,nip );
ltRecord->IP = QCTools::PCharToQString( nip );
if ( mac != NULL ){
QString DesMAC = QCTools::PCharToQString( mac );
ltRecord->MAC = DesMAC;
ltRecord->Organization = "";
ltRecord->HOSTNAME = QCTools::PCharToQString( testip->IPGetPCName( nip ) );
if( this->fPort != -9999 ){
if( this->fPortType == 1 ){
/** TCP **/
if( testSocket->TestTCPConnectPort( nip,fPort ) == 0 ){
qDebug() << " ======= TCP ======>" << nip << ":" << fPort << " OK";
emit notify( ltRecord );
}
}else{
/** UDP **/
if( testSocket->TestUDPSendPort( nip,fPort ) == 0 ){
qDebug() << " ======== UDP =====>" << nip << ":" << fPort << " OK";
emit notify( ltRecord );
}
}
}else{
/**
* 向主线程发送消息 ( 探测结果 )*/
emit notify( ltRecord );
}
}
/**
* 取下一个目标ip */
strcpy( nip ,testip->NextIPaddress( nip ) );
/** 向主线程发送消息 ( 正要探测的IP )*/
emit notifyNextIP( QCTools::PCharToQString( nip ) );
}
QThread::run();
}