-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (45 loc) · 1.66 KB
/
main.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
#
# Developed by Adam McKnight (@apmcknight) on gh.
# Software is Open Source, all I ask is that
# you make a back-link to my github if you
# deploy it to production use.
#
# If you find an issue, please open a Ticket
# PR's will be rejected if .gitignore is removed
# See the CONTRIBUTING.md for more info.
#
import socket
# Defines the Main Function
def main():
print("\n\n¯\_(ツ)_/¯")
print(" IS WAN UP")
print("Developed by Adam P. McKnight")
print("Support the project on GitHub: www.github.com/apmcknight/is-wan-up")
print("\n\nTo begin please make a selection...\n\n")
options = ["Check for WAN uplink: Type 1 or enter uplink", "Ping an Address: Type 2 or enter pingaddr", "Ping Default Gateway: Type 3 or enter pinggw", "To Stop, type 'stop' or enter 0"]
for o in options:
print(o)
menu_selection = input("\nEnter an Option: ")
print("\n\n")
menu(menu_selection)
def menu(menu_selection):
if(menu_selection == 0 or menu_selection == "Exit" or menu_selection == "exit" or menu_selection == "stop"):
exit()
if(menu_selection == 1):
test_func()
# Test Function, for development - will be removed for production use
def test_func():
print("\n\nThis is a test function\n\n")
# Defines a Function that will ping the gateway to see if there is a WAN uplink
check_duration = 80
def connection_established():
print("Checks Starting...")
print("Checking your connection to 1.1.1.1")
try:
socket.create_connection(("1.1.1.1", check_duration))
return True
except OSError:
return False
# Calls the main function
if __name__ == "__main__":
main()