1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonで接続しているWi-Fiの名前を取得する

Posted at

使うかわからないけどWiFiの名前を取得するときできるか探したら昔の自作モジュールに出てきた、、、全然記憶にない

import subprocess

try:
    wifi_name = next((line.split(":")[1].strip() for line in subprocess.run(["netsh", "wlan", "show", "interfaces"], capture_output=True, text=True, check=True).stdout.splitlines() if "SSID" in line), "none")
except subprocess.CalledProcessError:
    wifi_name = "none"

print("Wi-Fi:", wifi_name)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?