-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.py
120 lines (97 loc) · 2.86 KB
/
core.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
#!/usr/bin/python3
import concurrent.futures
import time
import platform
import subprocess
# from .pypiupdate import *
import argparse
import sys
__version__ = "20200929"
def ping_task(host):
param = "-n" if platform.system().lower() == "windows" else "-c"
ping = ["ping", param, "3", host]
ping_return_code = subprocess.run(
ping, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
if ping_return_code.returncode == 0:
print(host + " is up")
else:
if ping_return_code.returncode == 2:
print(host + " is down")
def make_hosts(site_number):
return [
site_number + ".apple.com",
site_number + ".icloud.com",
site_number + ".github.com",
site_number + ".microsoft.com",
site_number + ".reddit.com",
]
def vis(site_number):
return [
site_number + ".google.com",
]
def vis_scan():
try:
site_number = input("Please enter site number: ")
thread_worker(vis(site_number))
except KeyboardInterrupt:
exit("\nApp exited!")
cont = True
while cont == True:
try:
if not input("Do another scan? [Y/n]: ").lower() in ["y", "yes"]:
cont = False
exit()
else:
site_number = input("Please enter site number: ")
thread_worker(vis(site_number))
except KeyboardInterrupt:
exit("\nApp exited!")
def scan():
try:
site_number = input("Please enter site number: ")
thread_worker(make_hosts(site_number))
except KeyboardInterrupt:
exit("\nApp exited!")
cont = True
while cont == True:
try:
if not input("Do another scan? [Y/n]: ").lower() in ["y", "yes"]:
cont = False
exit()
else:
site_number = input("Please enter site number: ")
thread_worker(make_hosts(site_number))
except KeyboardInterrupt:
exit("\nApp exited!")
def thread_worker(hosts_list):
with concurrent.futures.ThreadPoolExecutor(max_workers=30) as executor:
for host in hosts_list:
executor.submit(ping_task, host)
def main():
formatter_class = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(formatter_class=formatter_class)
parser.add_argument(
"-u",
"--update",
dest="update",
action="store_true",
help="Update script from pypi",
)
parser.add_argument(
"-hy",
"--hype",
dest="vis",
action="store_true",
help="Ping hypervisors devices",
)
args = parser.parse_args()
# Check for updates
if args.update:
PypiUpdater("core", force_update=True)
if args.vis:
vis_scan()
if len(sys.argv) == 1:
scan()
if __name__ == "__main__":
main()