VB6 Winsock control, returning IP addresses

Associate
Joined
26 Feb 2004
Posts
970
Location
China (Qinhuangdao)
Hi,

I have an old piece of Visual Basic software which uses the Winsock control to return the local IP address of the PC it is being run on. However, since these days laptops have multiple IP addresses for different network adapters, it isn't working. It might pick up the Wifi IPv4 address, but not the LAN, etc.

I was hoping the solution would be as simple as adding another Winsock control and setting the local port to 1 (first control seems to be set as 0), but this isn't working.

I tried searching online, but VB6 is such an old software, all the results are about ten years old!

Any suggestions?
 
Excellent, after searching what you said, I found the following:

Set WMI = GetObject("winmgmts:\\.\root\cimv2")
Set qryWMI = WMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

For Each Item In qryWMI
LocalIP = Item.IPAddress(0)
Next

Set WMI = Nothing
Set qryWMI = Nothing

Simple, and works perfectly!
 
Back
Top Bottom