psutil은 실행중인 프로세스 및 시스템 자원 정보를 볼 수 있는 모듈
import psutil
strings = ''
stringsFormat = '%-30s\t%-20s\t%-10s\t%-20s\t%-10s\n'
strings = stringsFormat % ('process', 'local ip', 'local port', 'remote ip', 'remote port')
strings += '-'*30+'\t'+'-'*20+'\t'+'-'*10+'\t'+'-'*20+'\t'+'-'*10+'\n'
def processinfo():
process = psutil.Process(conn.pid)
return process.name()
for conn in psutil.net_connections():
if conn.status == 'NONE':
pass
else:
localip = conn.laddr[0]
localport = conn.laddr[1]
remoteip = conn.raddr[0] if conn.raddr else '-'
remoteport = conn.raddr[1] if conn.raddr else '-'
strings += stringsFormat % (processinfo(), localip, localport, remoteip, remoteport)
print(strings)
---------------------------------------------------------------------------------
process local ip local port remote ip remote port
------------------------------ -------------------- ---------- -------------------- ----------
chrome.exe x.x.x.x 60384 x.x.x.x 443
chrome.exe x.x.x.x 59517 x.x.x.x xxxx
.............................
'Python > Python for Windows' 카테고리의 다른 글
[Python] subprocess모듈과 7z을 이용한 전일 로그 자동 압축 보관 (0) | 2019.10.24 |
---|---|
[Python] subprocess모듈과 Bandizip을 이용한 전일 로그 자동 압축 보관 (0) | 2019.10.20 |
[Python] To send an attachment when mailing (0) | 2019.09.30 |
[Python] pandas를 이용한 iis-ftp log 파싱 (0) | 2019.09.16 |
[Python] Check ICMP using ping3 module, maria db and grafana (0) | 2019.08.25 |
[Python] winreg 모듈을 이용한 Windows 공유폴더 레지스트리 설정 점검 (0) | 2019.08.24 |
[Python] check ICMP using ping3 module. (파이썬을 이용한 ping 체크) (0) | 2019.08.19 |
윈도우 2012 NTP 서버 구축 (1) - 외부 인터넷 시간 동기화 설정 (0) | 2019.08.07 |