check_connections: on windows, use gopsutil to get tcp connections#419
Merged
Conversation
the library uses iphlpapi.dll functions GetTcpTable2, GetTcp6Table2, GetExtendedTcpTable. it also has GetExtendedUdpTable , but they are not used. the library transforms the connection states to english in common.go . the strings are always in english and not localized. this means check_connection can test for english strings in output without worry.
Contributor
Author
|
ci failing due to docker integration tests on linux, unrelated to PR. waiting for upstream fix. |
Contributor
|
Isn't that something the already included gopsutil lib can do: https://github.com/shirou/gopsutil/blob/master/net/net_windows.go Although net_connections is listed as not supported there seems to be a GetExtendedTcpTable in the mentioned code above win-netstat looks abandoned - last commit was 8 years ago |
gopsutil already has the same functionality and uses same windows api calls.
Contributor
Author
|
Thanks @c-kr Seems like you are correct. I had deepseek v4 pro look into sources, it confirms that it is using the same underlying functions for GetExtendedTcpTable and even converts the status to a string using same mappings from MSDN pushing a commit that changes library to gopsutil, took like 5 lines |
sni
approved these changes
Jul 17, 2026
Contributor
|
Great, one less sub process call. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
the library uses iphlpapi.dll functions GetTcpTable2, GetTcp6Table2, GetExtendedTcpTable. it also has GetExtendedUdpTable , but they are not used.
the library transforms the connection states to english in common.go . the strings are always in english and not localized. this means check_connection can test for english strings in connection.State without worry.
tested on a machine with german locale, it works. should fix #360
the library only imports standard packages and sys/windows , so it should be safe.