/
PortScanExample.py
142 lines (128 loc) 路 2.79 KB
/
PortScanExample.py
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from pyportscanner import pyscanner
def main():
# Initialize a Scanner object that will scan top 50 commonly used ports.
scanner = pyscanner.PortScanner(target_ports=100, verbose=True)
host_name = 'google.com'
message = 'put whatever message you want here'
'''
output contains a dictionary of {port:status} pairs
in which port is the list of ports we scanned
and status is either 'OPEN' or 'CLOSE'
'''
res = scanner.scan(host_name, message)
'''
************************************************************
Start scanning website: google.com
Server ip is: 172.217.6.110
80/TCP : OPEN
2000/UDP : OPEN
5060/UDP : OPEN
8008/TCP : OPEN
Host google.com scanned in 10.033627033233643 seconds
Scan completed!
'''
'''
> res
{9: 'CLOSE',
17: 'CLOSE',
19: 'CLOSE',
21: 'CLOSE',
22: 'CLOSE',
25: 'CLOSE',
26: 'CLOSE',
49: 'CLOSE',
53: 'CLOSE',
67: 'CLOSE',
68: 'CLOSE',
69: 'CLOSE',
80: 'OPEN',
81: 'CLOSE',
88: 'CLOSE',
110: 'CLOSE',
111: 'CLOSE',
113: 'CLOSE',
123: 'CLOSE',
135: 'CLOSE',
136: 'CLOSE',
137: 'CLOSE',
138: 'CLOSE',
139: 'CLOSE',
143: 'CLOSE',
158: 'CLOSE',
161: 'CLOSE',
162: 'CLOSE',
177: 'CLOSE',
179: 'CLOSE',
199: 'CLOSE',
427: 'CLOSE',
443: 'CLOSE',
445: 'CLOSE',
465: 'CLOSE',
514: 'CLOSE',
515: 'CLOSE',
518: 'CLOSE',
520: 'CLOSE',
548: 'CLOSE',
554: 'CLOSE',
587: 'CLOSE',
593: 'CLOSE',
623: 'CLOSE',
626: 'CLOSE',
631: 'CLOSE',
646: 'CLOSE',
993: 'CLOSE',
995: 'CLOSE',
999: 'CLOSE',
1022: 'CLOSE',
1025: 'CLOSE',
1026: 'CLOSE',
1027: 'CLOSE',
1029: 'CLOSE',
1030: 'CLOSE',
1031: 'CLOSE',
1032: 'CLOSE',
1433: 'CLOSE',
1434: 'CLOSE',
1645: 'CLOSE',
1646: 'CLOSE',
1718: 'CLOSE',
1719: 'CLOSE',
1720: 'CLOSE',
1723: 'CLOSE',
1812: 'CLOSE',
1813: 'CLOSE',
1900: 'CLOSE',
2000: 'OPEN',
2001: 'CLOSE',
2049: 'CLOSE',
2222: 'CLOSE',
2223: 'CLOSE',
3283: 'CLOSE',
3389: 'CLOSE',
3456: 'CLOSE',
3703: 'CLOSE',
4045: 'CLOSE',
4500: 'CLOSE',
5000: 'CLOSE',
5060: 'OPEN',
5353: 'CLOSE',
5355: 'CLOSE',
5666: 'CLOSE',
5900: 'CLOSE',
8000: 'CLOSE',
8008: 'OPEN',
8080: 'CLOSE',
8443: 'CLOSE',
8888: 'CLOSE',
9200: 'CLOSE',
10000: 'CLOSE',
17185: 'CLOSE',
20031: 'CLOSE',
31337: 'CLOSE',
32768: 'CLOSE',
32769: 'CLOSE',
32770: 'CLOSE',
32771: 'CLOSE'}
'''
if __name__ == "__main__":
main()