-
Notifications
You must be signed in to change notification settings - Fork 0
/
port_closer.py
48 lines (37 loc) · 1.03 KB
/
port_closer.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
#########################################################
#
# A function to close ports / sockets
#
# Version 01: 17 April 2019
# First pass
#
# Version 02:
# Return codes:
# 1 => error closing input ports
# 2 => error closing output ports
# 3 => error closing input and output ports
#
# Version 03: 18 April 2019
# Only needs to work with list of input sockets
#
# Version 03a: 19 April 2019
# Removed unnecessary imports
#########################################################
from routerbase import logger
def port_closer(socket_list):
for a_socket in socket_list:
try:
name = a_socket.getsockname()
a_socket.close()
logger("Closed socket / port, ", a_socket, "/", name)
except (Exception):
return 1
return 0
if __name__ == "__main__":
from port_opener import port_opener
# open input ports
input_ports = (3001, 4001, 5001)
socket_list = port_opener(input_ports)
logger(socket_list)
# input ports
port_closer(socket_list)