프로젝트 로그/테스트x솔루션 JIG 개발기
[Python] 로컬 컴퓨터 NIC(Network Interface Card)의 IP, 서브넷 등 정보 확인 방법
Life4IoT.rnd
2022. 8. 1. 20:12
반응형
psutil 모듈 설치
pip install psutil
psutil 사용 예제
import psutil
addrs = psutil.net_if_addrs()
print(addrs)
NIC 이름으로 해당 인터페이스 IP, SUBNET, GATEWAY 주소 가져오기
import socket
import psutil
def getNicInfo(nicName=''):
addrs = psutil.net_if_addrs()
if nicName in addrs:
for nicInfo in addrs[nicName]:
if nicInfo.family == socket.AddressFamily.AF_INET:
return True, nicInfo.address, nicInfo.netmask, nicInfo.broadcast
return False, None, None, None
print( getNicInfo(nicName="eth2") )
$ (twarelab_env) D:\Workspace\Test\NetworkTest>python test.py
$ (True, '192.168.100.200', '255.255.255.0', None)
반응형