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)
-------------------------------------------------------------
[ open ]
Open 22 : 2023-05-23 17:47:27
[ close ]
Close 80 : 2023-05-23 17:45:28
'Python > Python Programming' 카테고리의 다른 글
[ Python ] requests 모듈을 이용한 동영상 다운로드 (0) | 2023.05.25 |
---|---|
[ Python ] 정규식 이용한 IP address 마스킹(감추기) 하기 (3) | 2023.05.24 |
[ Python ] Prometheus metric 값 가져오기 (0) | 2023.05.24 |
[ Python ] Linux 파일 (스토리지) 연도별 개수와 총 용량 구하기 (0) | 2023.05.24 |
[ Python ] pandas DataFrame을 HTML 형식으로 export 하기. (모니터링 활용) (0) | 2023.05.17 |
[ Python ] 웹 서버 날짜 확인 하기 (0) | 2023.05.14 |
[ Python ] ntplib 모듈을 이용한 시간 동기화 점검 (0) | 2023.05.14 |
[ Python ] numpy를 이용한 1차원 배열 2 차원 배열로 변환 (0) | 2023.05.12 |