๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ› ๏ธ ์ž๋™ํ™” ๋ฐ ์Šคํฌ๋ฆฝํŠธ/๐Ÿงฐ Python

[Python] Windows ๋ฌด์„ ๋žœ ์–ด๋Œ‘ํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ / ํ™œ์„ฑํ™”

by Ji-Hoon 2024. 6. 30.

 

์ž‘์—… ๋ฐฐ๊ฒฝ

์‚ฌ์šฉ์ž PC์˜ ๋ฌด์„ ๋žœ์„ ํ™œ์„ฑํ™” ํ•ด์•ผํ•˜๋Š”๋ฐ...

Windows ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์ด ์—†๊ณ  User ๊ถŒํ•œ์ด๋ผ๋ฉด ํ™œ์„ฑํ™”๊ฐ€ ๋˜์ง€ ์•Š๋Š”๋‹ค ๐Ÿ˜ฃ

 

Python ์œผ๋กœ ๋ฌด์„ ๋žœ์„ ์กฐํšŒํ•ด์„œ ํ™œ์„ฑํ™” ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๊ตฌ๊ธ€๋ง ํ•ด์„œ ๋š๋”ฑ๊ฑฐ๋ ธ๋‹ค..

 

์žฅ์น˜๊ด€๋ฆฌ์ž์˜ ๋„คํŠธ์›Œํฌ ์–ด๋Œ‘ํ„ฐ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ

- ์žฅ์น˜ ๊ด€๋ฆฌ์ž์—์„œ ํ‘œ์‹œ๋˜๋Š” ์–ด๋Œ‘ํ„ฐ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

 

Windows ์žฅ์น˜ ๊ด€๋ฆฌ์ž

 

import tkinter as tk
import wmi

def show_network_adapters():
    # ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•  ์ฐฝ ์ƒ์„ฑ
    result_window = tk.Tk()
    result_window.title("๋„คํŠธ์›Œํฌ ์–ด๋Œ‘ํ„ฐ ์ •๋ณด")

    # WMI ๊ฐ์ฒด ์ƒ์„ฑ
    c = wmi.WMI()

    # Win32_NetworkAdapter ์ฟผ๋ฆฌ
    network_adapters = c.Win32_NetworkAdapter()

    # ๊ฒฐ๊ณผ๋ฅผ ํ…์ŠคํŠธ๋กœ ํ‘œ์‹œํ•  ๋ผ๋ฒจ ์ƒ์„ฑ
    result_label = tk.Label(result_window, text="๋„คํŠธ์›Œํฌ ์–ด๋Œ‘ํ„ฐ ์ •๋ณด:\n")
    result_label.pack()

    # ๋ชจ๋“  ๋„คํŠธ์›Œํฌ ์–ด๋Œ‘ํ„ฐ ์ •๋ณด ์ถœ๋ ฅ
    for adapter in network_adapters:
        adapter_info = f"์ด๋ฆ„: {adapter.Name}\n์ƒํƒœ: {adapter.NetConnectionStatus}\n" \
                       f"์„ค๋ช…: {adapter.Description}\nMAC ์ฃผ์†Œ: {adapter.MACAddress}\n\n"
        result_label = tk.Label(result_window, text=adapter_info)
        result_label.pack()

    result_window.mainloop()

# ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ํ•จ์ˆ˜ ์‹คํ–‰
root = tk.Tk()
root.title("๋„คํŠธ์›Œํฌ ์–ด๋Œ‘ํ„ฐ ์ •๋ณด ๋ณด๊ธฐ")

show_button = tk.Button(root, text="๋„คํŠธ์›Œํฌ ์–ด๋Œ‘ํ„ฐ ์ •๋ณด ๋ณด๊ธฐ", command=show_network_adapters)
show_button.pack()

root.mainloop()

 

 

๋ฌด์„ ๋žœ ์–ด๋Œ‘ํ„ฐ ํ™œ์„ฑํ™”

 

๋ฌด์„ ๋žœ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ ์™”์œผ๋‹ˆ ์ด์ œ ํ™œ์„ฑํ™”๋ฅผ ์‹œ์ผœ๋ณด์ž

 

1. ์žฅ์น˜๊ด€๋ฆฌ์ž์˜ ๋„คํŠธ์›Œํฌ ์–ด๋Œ‘ํ„ฐ ๋ฆฌ์ŠคํŠธ ์—…

2. "Intel(R) Wi-Fi" ๊ฐ€ ํฌํ•จ๋œ ๋„คํŠธ์›Œํฌ ์–ด๋Œ‘ํ„ฐ๋ฅผ ํ™œ์„ฑํ™” ํ•œ๋‹ค.

 

import wmi
import ctypes
import time

# WMI ๊ฐ์ฒด ์ƒ์„ฑ
c = wmi.WMI()

# Win32_NetworkAdapter ์ฟผ๋ฆฌ
network_adapters = c.Win32_NetworkAdapter()

for adapter in network_adapters:
    adapter_info = f"์ด๋ฆ„: {adapter.Name}\n์ƒํƒœ: {adapter.NetConnectionStatus}\n" \
                   f"์„ค๋ช…: {adapter.Description}\nMAC ์ฃผ์†Œ: {adapter.MACAddress}\n\n"
    # print(adapter_info)

    # ์›ํ•˜๋Š” ์–ด๋Œ‘ํ„ฐ์˜ ์ด๋ฆ„์œผ๋กœ ํ•„ํ„ฐ๋งํ•˜์—ฌ ๋น„ํ™œ์„ฑํ™” ๋˜๋Š” ์ œ๊ฑฐ ๊ฐ€๋Šฅ
    if "Intel(R) Wi-Fi" in adapter.Name:
        # ๋น„ํ™œ์„ฑํ™”
        # dapter.Disable()
        # print(f"{adapter.Name} ๋น„ํ™œ์„ฑํ™” ์™„๋ฃŒ")

        # time.sleep(5)

        # ํ™œ์„ฑํ™”
        adapter.Enable()
        # print(f"{adapter.Name} ํ™œ์„ฑํ™” ์™„๋ฃŒ")

 

๋Œ“๊ธ€