bgschiller
bgschiller

Reputation: 2127

Find name of current wifi network on Windows

I'd like to be able to determine the name of the current WiFi network using python. Subprocesses are acceptable. One mac, I'm able to do (in a subprocess)

networksetup -getairportnetwork en1

On windows, I haven't been able to find anything that works. The information doesn't seem to be in the output from ipconfig. I've also tried

netsh show wlan profiles name=*

but it gives the following error message:

The following command was not found: show wlan profiles name=*.

EDIT

So I had the parameter order backwards, should have been

netsh wlan show profiles name=*

This works, but only when I'm online. When I'm offline or connected to an ad-hoc network that doesn't provide internet access, I get the name of the most recently connected WiFi network.

Unfortunately, I'm going to be using this on ad-hoc networks in areas where I can't depend on an internet connection.

Upvotes: 3

Views: 5274

Answers (3)

dope
dope

Reputation: 186

Further to @Akshayanti's post, using python to get the name of the network specifically (the ESSID)

You can do this:

out = subprocess.check_output('netsh wlan show interfaces').decode("utf-8")
current = out.split("\n")[19].split(": ")[1]
print(f"Current WiFi Network: {current}")

You could condense this down further. But in essence, this is what you need to do.

Upvotes: 0

Akshayanti
Akshayanti

Reputation: 326

To get the name of current profile you're connected to, try-

netsh wlan show interfaces

and see the last line. The Profile name you're connected to will be visible. In case, you're disconnected, this field will not be visible.

Upvotes: 6

RonenKr
RonenKr

Reputation: 213

try this:

netsh wlan show profiles name=*

Upvotes: 1

Related Questions