[Bug?] serverName cannot be an IPv4 address
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- go
- Domain
- operating-systems
Research direction
Start at pkg/wmiinstance/WmiSession.go line 83, where ServerName and Domain are joined, and review the Test_ConnectionIpV4 example in the issue. Reproduce the connection with 127.0.0.1 and verify that IPv4 ServerName values connect successfully while hostname behavior remains intact.
Written by the indexing model from the issue text.
Description
Hi there,
I happened to notice that the wmiSession's Connect() method does not seem to work when we specify as a ServerName an IPv4 address.
Indeed the following snippet:
package cim
import (
"fmt"
"log"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_ConnectionIpV4(t *testing.T) {
sm := NewWmiSessionManager()
defer sm.Close()
defer sm.Dispose()
session, err := sm.GetSession("root\\cimv2", "127.0.0.1", "", "", "")
if err != nil {
log.Printf("Could not get session %v", err)
return
}
_, err = session.Connect()
assert.Nil(t, err, fmt.Sprintf("Err should be nil %v", err))
if err != nil {
log.Printf("Could not connect session %v", err)
return
}
defer session.Close()
defer session.Dispose()
}
Fails with the following error:
=== RUN Test_ClassDoesNotExist
c:\Users\mirko.bez\github\herrBez\wmi\pkg\wmiinstance\WmiSession_test.go:22:
Error Trace: WmiSession_test.go:22
Error: Expected nil, but got: &ole.OleError{hr:0x80020009, description:"The RPC server is unavailable. ", subError:ole.EXCEPINFO{wCode:0x0, wReserved:0x0, bstrSource:(*uint16)(nil), bstrDescription:(*uint16)(nil), bstrHelpFile:(*uint16)(nil), dwHelpContext:0x0, pvReserved:0x0, pfnDeferredFillIn:0x0, scode:0x800706ba, rendered:true, source:"SWbemLocator", description:"The RPC server is unavailable. ", helpFile:"<nil>"}}
Test: Test_ClassDoesNotExist
Messages: Err should be nil Exception occurred. (The RPC server is unavailable. )
2025/02/10 11:01:47 Could not connect session Exception occurred. (The RPC server is unavailable. )
--- FAIL: Test_ClassDoesNotExist (0.07s)
FAIL
FAIL github.com/microsoft/wmi/pkg/wmiinstance 0.093s
This seems caused by the following line https://github.com/microsoft/wmi/blob/0671b0c1c57be7e248afdb57cecc3d12b8c96af9/pkg/wmiinstance/WmiSession.go#L83. In particular by the strings.Join([]string{c.ServerName, c.Domain}, ".").
Indeed, no matter if domain is the empty string or not, the method adds as a suffix a dot. While this work fine for hostnames (e.g., localhost. does work), it seems that with IPv4 addresses this is causing the error 0x800706ba https://support.microsoft.com/en-us/topic/fix-error-code-0x800706ba-may-be-generated-when-a-client-computer-makes-a-request-to-a-remote-com-object-f84b2895-4e72-653d-200e-6216c91ce4bb, clearly indicating that we are not reaching the intended server.
I confirmed that this is the case by using the WMI Explorer (127.0.0.1 works fine while 127.0.0.1. returns an error):
Workaround
As a workaround to make use of IPv4 addresses, we can specify the domain as the last octet of the ipv4 address.
func Test_ConnectionIpV4(t *testing.T) {
sm := NewWmiSessionManager()
defer sm.Close()
defer sm.Dispose()
session, err := sm.GetSession("root\\cimv2", "127.0.0", "1", "", "")
if err != nil {
log.Printf("Could not get session %v", err)
return
}
_, err = session.Connect()
assert.Nil(t, err, fmt.Sprintf("Err should be nil %v", err))
if err != nil {
log.Printf("Could not connect session %v", err)
return
}
defer session.Close()
defer session.Dispose()
}
- Dominant language
- Go
- Stars
- 58
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/wmi
-
Disk ID & Baseboard Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100