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

Disable PowerShell profile and simplify fingerprinting link speed on Windows #11183

Merged
merged 4 commits into from
Sep 22, 2021

Conversation

lgfa29
Copy link
Contributor

@lgfa29 lgfa29 commented Sep 14, 2021

Fingerprinting link speed on Windows relies on running a PowerShell command and parsing its output.

If the user has any PowerShell profile that outputs anything to the console, this process will fail. This PR adds the -NoProfile parameter to avoid loading user profile when running the command.

Link speeds are also not always integers, such as in the case of WiFi network cards, so this PRs changes the value parsing to use ParseFloat.

Get-NetAdapter returns a property called Speed, which always returns the link speed in bytes/s, making parsing the command output easier.

Closes #11171

@randomchance
Copy link

Thanks!

Couple of things that may be helpful, although my experience is all PowerShell/C#, not go.
You can avoid parsing it as a float if you use the Speed property instead of LinkSpeed, Speed is the raw bytes per second value.

If you want to check for other places you may have a better option, you can pipe any object to Get-Member for it's definition.
You can also use Select-Object * to dump all the values (except hidden properties), bypassing object-specific formatting that normally hides the non-human readable stuff.

Since the Where-Object clause is an explicit equals (not -like or -match ) you can skip it by requesting the adapter directly by name:

PS> Get-NetAdapter -Name 'vEthernet (WiredNetwork)' -ErrorAction Ignore | Select-Object -ExpandProperty 'Speed'
1000000000

I used -ErrorAction Ignore so that any errors, such as not finding an adapter by that name, are silent.

Slightly related note, I would love if this could log the names it's looking for at a debug level; then a new user would be able to see what values are allowed if they need to specify the adapter manually. Alternatively, you could explicitly say to use the "Interface Alias on Windows, not the "Interface Name". I fully admit that this was probably me overthinking things, because the InterfaceName is normally something like ethernet_32778.

@lgfa29
Copy link
Contributor Author

lgfa29 commented Sep 16, 2021

Oh thank you so much for the tips. My knowledge of PowerShell is quite limited, so always good to learn new things 🙂

Slightly related note, I would love if this could log the names it's looking for at a debug level;

Yup, I noticed this too while working on this, so I also opened #11184 😄

That PR adds a new field to log messages to display the device name during fingerprinting. Is this what you were looking for?

@lgfa29 lgfa29 marked this pull request as draft September 16, 2021 14:54
@vercel vercel bot temporarily deployed to Preview – nomad September 16, 2021 19:27 Inactive
@lgfa29 lgfa29 marked this pull request as ready for review September 16, 2021 19:28
@lgfa29 lgfa29 changed the title Disable PowerShell profile and allow decimal values when fingerprinting link speed on Windows Disable PowerShell profile and simplify fingerprinting link speed on Windows Sep 16, 2021
Copy link
Contributor

@DerekStrickland DerekStrickland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job simplifying this!

@lgfa29
Copy link
Contributor Author

lgfa29 commented Sep 22, 2021

Nice job simplifying this!

100% of the credit goes to @randomchance. I just typed words 🙃

@lgfa29 lgfa29 added this to the 1.2.0 milestone Sep 22, 2021
@lgfa29 lgfa29 merged commit 2904a07 into main Sep 22, 2021
@lgfa29 lgfa29 deleted the fix-win-net-speed branch September 22, 2021 15:17
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LinkSpeed Detection on Windows includes all PowerShell profile output for each interface
3 participants