Skip to content

check_connections: on windows, use gopsutil to get tcp connections#419

Merged
sni merged 3 commits into
mainfrom
check-connections-windows-netstat-library
Jul 17, 2026
Merged

check_connections: on windows, use gopsutil to get tcp connections#419
sni merged 3 commits into
mainfrom
check-connections-windows-netstat-library

Conversation

@inqrphl

@inqrphl inqrphl commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@inqrphl

inqrphl commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

ci failing due to docker integration tests on linux, unrelated to PR. waiting for upstream fix.

@c-kr

c-kr commented Jul 17, 2026

Copy link
Copy Markdown
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.
@inqrphl

inqrphl commented Jul 17, 2026

Copy link
Copy Markdown
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

@inqrphl inqrphl changed the title check_connections: on windows, use win-netstat library check_connections: on windows, use gopsutil to get tcp connections Jul 17, 2026
@sni
sni merged commit 77f93a0 into main Jul 17, 2026
149 checks passed
@sni

sni commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Great, one less sub process call. Thanks.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG REPORT: check_connections on German Windows locale reports "unhandled tcp state: HERGESTELLT" and returns 0 for state counters

3 participants