컴퓨터 & 서버/Python
(초급) python으로 시스템 정보 확인하기
freeseaboy
2024. 10. 24. 17:36
반응형
파이썬으로 로컬(내)PC 정보 확인하는 프로그램을 제작하겠다.
확인할수 있는 정보 리스트
- IP
- 외부 네트워크 연결 상태
- 현재 등록된 DNS 정보
- 호스트이름
- 윈도우 버전
파이썬 버전 3을 이용하고 GUI 구현은 추후에
이번 포스팅은 CLI 버전이라고 보면 된다.
바로 들어가보자.
import socket
import subprocess
import platform
import os
import requests
def get_ip():
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
return ip_address
def check_network_connection():
try:
requests.get("https://www.google.com", timeout=5)
return "Connection OK"
except requests.ConnectionError:
return "Not Connected"
def get_dns_info():
result = subprocess.check_output("nslookup", shell=True, text=True)
return result
def get_hostname():
return socket.gethostname()
def get_windows_version():
return platform.platform()
def main():
print("my ip:", get_ip())
print("wan connection status:", check_network_connection())
print("dns info:\n", get_dns_info())
print("my hostname:", get_hostname())
print("my winversion:", get_windows_version())
if __name__ == "__main__":
main()
위코드를 작성후 xxx.py 로 이름을 지정후 실행해보자.
아주 잘된다...
만약 문제가 있다면....
네트워크 설정이나 OS부분을 한번 찾아봐야 할것이다.
반응형