Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows 10 Pro] Incorrect WiFi IP address reporting when not connected or turned off #2136

Closed
Sighi-04 opened this issue Sep 6, 2022 · 5 comments

Comments

@Sighi-04
Copy link

Sighi-04 commented Sep 6, 2022

Summary

  • OS: Windows 10 Pro 64 bit (tested and working correctly on Ubuntu 22.04 LTS)
  • Architecture: 64 bit Intel X86
  • Psutil version: 5.9.2
  • Python version: 3.7.9
  • Type: core

Description

net_if_addrs() reports last assigned IP address for WiFi interface even when it's not connected or turned off. I'm attaching 3 screenshots in which i start from my studio wifi, move over to my phone's hotspot and then turn off wifi, checking the IP address of the WiFi NIC in every step.

Studio WiFi

1  Wifi

Phone Hotspot

2  Hotspot

WiFi off

3  Turned off

You can see that after turning WiFi off it still reports the last IP address (in this case the one assigned by my phone).

In case it matters, my WiFi card is an Intel WiFi 6 AX200.

@Sighi-04 Sighi-04 added the bug label Sep 6, 2022
@Sighi-04 Sighi-04 changed the title [Windows 10 Pro] title [Windows 10 Pro] Incorrect WiFi IP address reporting when not connected or turned off Sep 6, 2022
@giampaolo
Copy link
Owner

I think it doesn't matter whether the NIC interface is active or not. I guess IP probably remains assigned. Does ipconfig /all show the IP address?
NIC / IP addresses come from GetAdapterAddresses, BTW, and this function is used by psutil.net_if_addrs() and psutil.net_io_counters()`.

@Sighi-04
Copy link
Author

Sighi-04 commented Sep 19, 2022

Screenshot
ipconfig /all does say that the card is disconnected/disabled, while psutil keeps reporting the last assigned IP address. Maybe this is a problem with the Windows API?
I have moved to Windows 11 but predictably the results are the same.

@giampaolo
Copy link
Owner

ipconfig /all does say that the card is disconnected/disabled, while psutil keeps reporting the last assigned IP address.

psutil.net_if_stats() can be used to check whether an NIC is active / running or not.
What's the output of this?

>>> psutil.net_if_stats()["Wi-Fi"].isup

@Sighi-04
Copy link
Author

It does correctly return false when wifi is disabled. So for my usecase I can use the isup property from net_if_stats() to exclude unassigned ip addresses. I imagine this wouldn't be a top priority especially for you/your team, but checking if the interface is up before returning related IP addresses would be nice. Maybe if I ever get to it I could submit a PR.

@giampaolo
Copy link
Owner

Actually psutil.net_if_addrs() doesn't make any promise about whether the returned NICs are up.
It's debatable, but I'm more keen on considering this "not a bug". Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants