check
-
[ Python ] socket 모듈을 이용한 Port open / close checkPython/Python Programming 2023. 5. 23. 17:49
import socket from datetime import datetime import time checkTime = str(datetime.today())[:19] ipadd = '127.0.0.1' # IP Address, string port = 80 # Port Number, interger sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(5) res = sock.connect_ex((ipadd, port)) text = str(port) + ' : ' + checkTime print('Open ' + text if res == 0 else 'Close ' + text) -----------------------..