-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckipaddress.cpp
128 lines (111 loc) · 3.53 KB
/
checkipaddress.cpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "checkipaddress.h"
#include "qvariant.h"
#include <QString>
IPAddress::IPAddress()
{
firstBit = 0;
secondBit = 0;
thirdBit = 0;
fourthBit = 0;
}
IPAddress::IPAddress(unsigned short one, unsigned short two, unsigned short three, unsigned short four){
firstBit = one;
secondBit = two;
thirdBit = three;
fourthBit = four;
}
unsigned short IPAddress::getFBit (){return firstBit;}
unsigned short IPAddress::getSBit (){return secondBit;}
unsigned short IPAddress::getThBit (){return thirdBit;}
unsigned short IPAddress::getFoBit (){return fourthBit;}
QString IPAddress::printIpAddress(){
QString info = "Nan";
return info;
}
void IPAddressChecked::setCheck(bool newCheck){check = newCheck;}
bool IPAddressChecked::getCheck(){return check;}
QString IPAddressChecked::classACheck (){
QString info;
if (getFBit() >= 0 && getFBit() <= 127 && getSBit() <= 255 && getThBit() <= 255 && getFoBit() <=255){
setCheck(true);
info = QVariant(getCheck()).toString();
return info;
}else{
setCheck(false);
info = QVariant(getCheck()).toString();
return info;
}
}
QString IPAddressChecked::classBCheck (){
QString info;
if (getFBit() >= 128 && getFBit() <= 191 && getThBit() <= 255 && getFoBit() <=255){
if(getSBit() >= 0 && getSBit() <= 255){
setCheck(true);
info = QVariant(getCheck()).toString();
return info;
}else{
setCheck(false);
info = QVariant(getCheck()).toString();
return info;
}
}else{
setCheck(false);
info = QVariant(getCheck()).toString();
return info;
}
}
QString IPAddressChecked::classCCheck (){
QString info;
if (getFBit() >= 192 && getFBit() <= 223 && getFoBit() <=255){
if(getSBit() >= 0 && getSBit() <= 255){
if(getThBit() >= 0 && getThBit() <= 255){
setCheck(true);
info = QVariant(getCheck()).toString();
return info;
}else{
setCheck(false);
info = QVariant(getCheck()).toString();
return info;
}
}else{
setCheck(false);
info = QVariant(getCheck()).toString();
return info;
}
}else{
setCheck(false);
info = QVariant(getCheck()).toString();
return info;
}
}
QString IPAddressChecked::classDCheck (){
QString info;
if (getFBit() >= 224 && getFBit() <= 239 && getSBit() <= 255 && getThBit() <= 255 && getFoBit() <=255){
setCheck(true);
info = QVariant(getCheck()).toString();
return info;
}else{
setCheck(false);
info = QVariant(getCheck()).toString();
return info;
}
}
QString IPAddressChecked::classECheck (){
QString info;
if (getFBit() >= 240 && getFBit() <= 255 && getSBit() <= 255 && getThBit() <= 255 && getFoBit() <=255){
setCheck(true);
info = QVariant(getCheck()).toString();
return info;
}else{
setCheck(false);
info = QVariant(getCheck()).toString();
return info;
}
}
QString IPAddressChecked::printIpAddress(){
QString info = QString::number(firstBit) + "." + QString::number(secondBit) + "." + QString::number(thirdBit) + "." + QString::number(fourthBit) + " - ";
return info;
}
IPAddressChecked::IPAddressChecked(){
check = false;
}