How to get local ip addresses

I followed the NetworkInterface example in the the docs but its only returning my machine the others just come back as 0.0.0.0 for the IP and the MAC address’s are wrong
Now its a wireless network so that’s maybe why? if that’s the case is it possible to do something that can handle both wireless and wired?
This machine runs Win 10, the others are Win7, Win8.1… it probably need to work on Mac at some point

On windows. What do you get if you enter this command: ipconfig /all in a cmd (command) prompt

This code works fine for me.

  Dim count As Integer
  Dim s as String
  
  count = System.NetworkInterfaceCount
  
  For i As Integer = 0 To count-1
    s = s + "Network Interface No: " + str(i) + EndOfLine
    s = s + System.GetNetworkInterface(i).IPAddress + EndOfLine
    s = s + System.GetNetworkInterface(i).MACAddress + EndOfLine
    s = s + System.GetNetworkInterface(i).SubnetMask + EndOfLine + EndOfLine
  Next
  
  msgbox s

But this above example will only show connected networks with an IP address. Otherwise it is 0.0.0.0

If you need more informations of your network interface card. You can on Windows use WMI See link: https://msdn.microsoft.com/en-us/library/aa394218(v=vs.85).aspx . How to use WMI with OLEobject. You will find some example on this forum, if you search for WMI. Here are some links:

  1. https://forum.xojo.com/18937-how-can-i-access-a-volume-by-name/p1#p159106
  2. https://forum.xojo.com/18981-cpu-temperature/p1#p159341
  3. https://forum.xojo.com/4447-shell-issue/p1#p30972

Its not showing any of the network machines, really weird as the sharing works along with network rendering which can be fussy[code]Windows IP Configuration

Host Name . . . . . . . . . . . . : xxxx
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Wireless LAN adapter Wireless Network Connection 4:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Virtual WiFi Miniport Adapter #
2
Physical Address. . . . . . . . . : 94-FB-B2-86-25-D6
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Wireless Network Connection 3:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : BT Dual-Band Wi-Fi Dongle
Physical Address. . . . . . . . . : 94-FB-B2-86-25-D6
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::f1bc:d69:92c9:9b5a%20(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.0.5(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : 21 January 2015 08:15:44
Lease Expires . . . . . . . . . . : 25 January 2015 08:15:47
Default Gateway . . . . . . . . . : 192.168.0.1
DHCP Server . . . . . . . . . . . : 192.168.0.1
DHCPv6 IAID . . . . . . . . . . . : 546634674
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-18-66-4D-D3-90-F6-52-31-CB-ED

DNS Servers . . . . . . . . . . . : 192.168.0.1
NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Local Area Connection:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller
Physical Address. . . . . . . . . : 10-BF-48-BA-C5-62
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{4E31E4E1-F6F3-4594-B7FE-DCD8FB8F8287}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft ISATAP Adapter
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

Tunnel adapter Local Area Connection* 9:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
IPv6 Address. . . . . . . . . . . : 2001:0:5ef5:79fd:280e:376b:ae92:dddf(Pref
erred)
Link-local IPv6 Address . . . . . : fe80::280e:376b:ae92:dddf%15(Preferred)
Default Gateway . . . . . . . . . : ::
NetBIOS over Tcpip. . . . . . . . : Disabled

Tunnel adapter isatap.{BBF4147E-6D60-46A4-899C-A96AACA15AA8}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #3
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{E653B21A-D5CB-4256-A279-ADF165866DD4}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes

C:\>[/code]

If I understand it correctly. The Xojo code does not display the ip address of: Wireless LAN adapter Wireless Network Connection 3 which is the only network interface that is connected at the moment… Hmm. I wonder if there is a virus checker in between that stops xojo for getting the info.

What happen if you switch off your firewall and virus checker on the PC. And then run your Xojo code.

How many System.NetworkInterfaceCount do you get ?

The 2 other things I was getting listed were the Ethernet and the mini port, not the other computers, I tried with the firewall and anti virus off and its just the same… I’ll see if I can find a cable and see if it work that way
To be honest the application would be used on a wired network but obviously it would be easier for me to test wireless, either that or buy enough cable to go around the house lol

if you need an alternative, maybe check NetworkInterfaceMBS class?
http://www.monkeybreadsoftware.net/class-networkinterfacembs.shtml

to get current IP of computer, I normally use local address property of socket classes.

From what I can see here, Windows does not show in the Network and Sharing Center the Mac that is attached to the same router through WiFi but is not part of the HomeGroup.

I can get computer/device names but not the IP… even C# doesn’t want to play… the big difference is these programs go un responsive so maybe something has changed
Its no biggy, it was just a “I wonder if” idea to assign render tasks to different machines, I can guess what the ip’s are at this stage I’ve got a long way to go before I need it automated :slight_smile:

I compiled an example with WMI. Have a try with this one:

  // WMI Win32_NetworkAdapterConfiguration
  //
  //
  //https://msdn.microsoft.com/en-us/library/aa394217%28v=vs.85%29.aspx
  
  Dim locator, objWMIService, objs, objProperty  As OLEOBJECT
  Dim nobjs as Integer
  
  //  Connect to WMI
  locator = new oleObject("WbemScripting.SWbemlocator", true)
  
  Dim wmiServiceParams(2) as variant
  wmiServiceParams(1) = "."
  wmiServiceParams(2) = "root\\cimv2"
  
  objWMIService= locator.invoke("ConnectServer", wmiServiceParams)
  
  // Run the WMI query
  objs = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE ")
  
  nobjs = objs.count - 1
  
  msgbox ("Number of Objects: " + str(nobjs +1))
  
  For i as integer = 0 to nobjs
    Dim stringData As String
    Dim IPAddrArray(-1), IPSubnetArray(-1), DNSServerSearchOrderArray(-1), DefaultIPGatewayArray(-1) As Variant
    Dim IPAddrStr, IPSubnetStr,  DNSServerSearchOrderStr, DefaultIPGatewayStr As String
    
    objProperty = objs.ItemIndex(i)
    // ItemIndex() is not supported in Windows XP only from Windows Vista and upwards
    
    IPAddrArray  = objProperty.ValueArray("IPAddress") 
    If IPAddrArray.Ubound <> -1 Then
      For Each IP As String In IPAddrArray
        IPAddrStr = IPAddrStr + IP + "  "
      Next
    End if
    
    IPSubnetArray = objProperty.ValueArray("IPSubnet")
    If IPSubnetArray.Ubound <> -1 Then
      For Each IPSubnet As String In IPSubnetArray
        IPSubnetStr = IPSubnetStr + IPSubnet + "  "
      Next
    End if
    
    DNSServerSearchOrderArray = objProperty.ValueArray("DNSServerSearchOrder")
    If DNSServerSearchOrderArray.Ubound <> -1 Then
      For Each DNSsso As String In DNSServerSearchOrderArray 
        DNSServerSearchOrderStr = DNSServerSearchOrderStr+ DNSsso + "  "
      Next
    End if
    
    DefaultIPGatewayArray = objProperty.ValueArray("DefaultIPGateway")
    If DefaultIPGatewayArray.Ubound <> -1 Then
      For Each DefIPg As String In DefaultIPGatewayArray
        DefaultIPGatewayStr = DefaultIPGatewayStr + DefIPg+ "  "
      Next
    End if
    
    // The Lines that is commented out is an Array
    stringData = "Network Adapter No: " +str(i+1) + EndOfLine _
    +"ArpAlwaysSourceRoute: " + objProperty.Value("ArpAlwaysSourceRoute") + EndOfLine _
    + "ArpUseEtherSNAP: " +  objProperty.Value("ArpUseEtherSNAP") + EndOfLine _
    + "Caption: " +  objProperty.Value("Caption") + EndOfLine _
    +"DatabasePath: "  + objProperty.Value("DatabasePath") + EndOfLine _
    + "DeadGWDetectEnabled: " +  objProperty.Value("DeadGWDetectEnabled") + EndOfLine _ 
    + "DefaultIPGateway: " + DefaultIPGatewayStr  + EndOfLine _
    + "DefaultTOS: " + objProperty.Value("DefaultTOS") + EndOfLine _
    + "DefaultTTL: " + objProperty.Value("DefaultTTL") + EndOfLine _
    + "Description: " + objProperty.Value("Description") + EndOfLine _
    + "DHCPEnabled: " + objProperty.Value("DHCPEnabled") + EndOfLine _
    + "DHCPLeaseExpires: " + objProperty.Value("DHCPLeaseExpires") + EndOfLine _
    + "DHCPLeaseObtained: " +  objProperty.Value("DHCPLeaseObtained") + EndOfLine _
    + "DHCPServer: " +  objProperty.Value("DHCPServer") + EndOfLine _
    + "DNSDomain: " +  objProperty.Value("DNSDomain") + EndOfLine _ 
    _//+ "DNSDomainSuffixSearchOrder: " + objProperty.Value("DNSDomainSuffixSearchOrder") + EndOfLine _
    + "DNSEnabledForWINSResolution: " + objProperty.Value("DNSEnabledForWINSResolution") + EndOfLine _
    + "DNSHostName: " + objProperty.Value("DNSHostName") + EndOfLine _ 
    + "DNSServerSearchOrder: " + DNSServerSearchOrderStr + EndOfLine _
    + "DomainDNSRegistrationEnabled: " + objProperty.Value("DomainDNSRegistrationEnabled") + EndOfLine _
    + "ForwardBufferMemory: " + objProperty.Value("ForwardBufferMemory") + EndOfLine _
    + "FullDNSRegistrationEnabled: " + objProperty.Value("FullDNSRegistrationEnabled") + EndOfLine _ 
    _//+ "GatewayCostMetric: " + objProperty.Value("GatewayCostMetric") + EndOfLine _
    + "IGMPLevel: " + objProperty.Value("IGMPLevel") + EndOfLine _
    + "Index: " + objProperty.Value("Index") + EndOfLine _
    + "IPAddress: " + IPAddrStr + EndOfLine _
    + "IPConnectionMetric: " + objProperty.Value("IPConnectionMetric") + EndOfLine _
    + "IPEnabled: " + objProperty.Value("IPEnabled") + EndOfLine _
    _'+ "IPFilterSecurityEnabled: " + objProperty.Value("IPFilterSecurityEnabled") + EndOfLine _
    _'+ "IPPortSecurityEnabled: " + objProperty.Value("IPPortSecurityEnabled") + EndOfLine _
    _'+ "IPSecPermitIPProtocols: " + objProperty.Value("IPSecPermitIPProtocols") + EndOfLine _
    _'+ "IPSecPermitTCPPorts: " + objProperty.Value("IPSecPermitTCPPorts") + EndOfLine _
    _'+ "IPSecPermitUDPPorts: " + objProperty.Value("IPSecPermitUDPPorts") + EndOfLine _
    + "IPSubnet: " + IPSubnetStr + EndOfLine _
    + "IPUseZeroBroadcast: " + objProperty.Value("IPUseZeroBroadcast") + EndOfLine _
    + "IPXAddress: " + objProperty.Value("IPXAddress") + EndOfLine _
    + "IPXEnabled: " + objProperty.Value("IPXEnabled") + EndOfLine _
    _//+ "IPXFrameType: " + objProperty.Value("IPXFrameType") + EndOfLine _
    + "IPXMediaType: " + objProperty.Value("IPXMediaType") + EndOfLine _
    _//+ "IPXMediaType: " + objProperty.Value("IPXMediaType") + EndOfLine _
    + "IPXVirtualNetNumber: " + objProperty.Value("IPXVirtualNetNumber") + EndOfLine _
    + "KeepAliveInterval: " + objProperty.Value("KeepAliveInterval") + EndOfLine _
    + "KeepAliveTime: " + objProperty.Value("KeepAliveTime") + EndOfLine _
    + "MACAddress: " + objProperty.Value("MACAddress") + EndOfLine _
    + "MTU: " + objProperty.Value("MTU") + EndOfLine _
    + "NumForwardPackets: " + objProperty.Value("NumForwardPackets") + EndOfLine _
    + "PMTUBHDetectEnabled: " + objProperty.Value("PMTUBHDetectEnabled") + EndOfLine _
    + "PMTUDiscoveryEnabled: " + objProperty.Value("PMTUDiscoveryEnabled") + EndOfLine _
    + "ServiceName: " + objProperty.Value("ServiceName") + EndOfLine _
    + "SettingID: " + objProperty.Value("SettingID") + EndOfLine _
    + "TcpipNetbiosOptions: " + objProperty.Value("TcpipNetbiosOptions") + EndOfLine _
    + "TcpMaxConnectRetransmissions: " + objProperty.Value("TcpMaxConnectRetransmissions") + EndOfLine _
    + "TcpMaxDataRetransmissions: " + objProperty.Value("TcpMaxDataRetransmissions") + EndOfLine _
    + "TcpNumConnections: " + objProperty.Value("TcpNumConnections") + EndOfLine _
    + "TcpUseRFC1122UrgentPointer: " + objProperty.Value("TcpUseRFC1122UrgentPointer") + EndOfLine _
    + "TcpWindowSize: " + objProperty.Value("TcpWindowSize") + EndOfLine _
    + "WINSEnableLMHostsLookup: " + objProperty.Value("WINSEnableLMHostsLookup") + EndOfLine _
    + "WINSHostLookupFile: " + objProperty.Value("WINSHostLookupFile") + EndOfLine _
    + "WINSPrimaryServer: " + objProperty.Value("WINSPrimaryServer") + EndOfLine _
    + "WINSScopeID: " + objProperty.Value("WINSScopeID") + EndOfLine _
    + "WINSSecondaryServer: " + objProperty.Value("WINSSecondaryServer") + EndOfLine
    
    
    //msgbox stringData
    
    TextArea1.AppendText(stringData) + EndOfLine  +EndOfLine
    
  Next
  
  locator = Nil
  
  exception err as oleexception
    msgbox err.message

Interesting. I just found out that with RealStudio2012R2.1, the above code will not work where you have returned arrays. Seems I have to force myself using Xojo more than RealStudio

Thanks John, I’m just on sorting my network, apparently the router is blocking discovery, its a Virgin media/Netgear one so there’s hidden stuff I’ve not found yet

Thanks to the example given by @John Hansen I was able to write a program to change the IP address of an adapter to static or revert it back to DHCP. Much appreciated.

I thought I would share, I’ll add the full source to the program I wrote to download from my blog eventually.

Change IP address (static IP):

[code] // WMI Win32_NetworkAdapterConfiguration
//
//
//https://msdn.microsoft.com/en-us/library/aa394217%28v=vs.85%29.aspx

	Dim locator, objWMIService, objNetAdapters, objProperty As OLEOBJECT
	Dim nobjs As Integer
	
	//  Connect to WMI
	locator = New oleObject("WbemScripting.SWbemlocator", True)
	
	Dim wmiServiceParams(0) As Variant
	wmiServiceParams(0) = "winmgmts:\\\\.\\root\\cimv2"
	
	Dim strResult As String
	Dim strSelect As String
	Dim lngEnable As Int32
	
	Dim strIP As String
	Dim strSubnet As String
	Dim strGateway As String
	Dim strDNS1 As String
	Dim strDNS2 As String
	
	strIP = Trim(txtIP.Text)
	strSubnet = Trim(txtSubnet.Text)
	strGateway = Trim(txtGateway.Text)
	strDNS1 = Trim(txtDNS1.Text)
	strDNS2 = Trim(txtDNS2.Text)
	
	Dim strIPArr() As String
	Dim strSubnetArr() As String
	Dim strGatewayArr() As String
	Dim strDNSArr() As String
	
	Dim isDNS As Boolean = False
	
	if strIP <> "" then
	strIPArr.Append(strIP)
	else
	txtInfo.Text = "Please enter IP Address to continue..."
	end
	
	if strSubnet <> "" then
	strSubnetArr.Append(strSubnet)
	else
	txtInfo.Text = "Please enter subnet to continue..."
	end
	
	if strGateway <> "" then
	strGatewayArr.Append(strGateway)
	else
	txtInfo.Text = "Please enter gateway to continue..."
	end
	
	if strDNS1 <> "" then
	strDNSArr.Append(strDNS1)
	isDNS = True
	end
	
	if strDNS2 <> "" then
	strDNSArr.Append(strDNS2)
	end
	
	objWMIService = locator.invoke("ConnectServer", wmiServiceParams)
	strSelect = "Select * from Win32_NetworkAdapterConfiguration where Index="+strIdx
	objNetAdapters = objWMIService.ExecQuery(strSelect)
	
	objProperty = objNetAdapters.ItemIndex(0)
	
	lngEnable = objProperty.EnableStatic(strIPArr, strSubnetArr)
	strResult = GetResult(lngEnable)
	txtInfo.AppendText("IP Result: " + str(lngEnable)) + EndOfLine
	txtInfo.AppendText(strResult) + EndOfLine
	
	lngEnable = objProperty.SetGateways(strGatewayArr)
	strResult = GetResult(lngEnable)
	txtInfo.AppendText("Gateway Result: " + str(lngEnable)) + EndOfLine
	txtInfo.AppendText(strResult) + EndOfLine
	
	if isDNS = True then
			lngEnable = objProperty.SetDNSServerSearchOrder(strDNSArr)
			strResult = GetResult(lngEnable)
			txtInfo.AppendText("DNS Result: " + str(lngEnable)) + EndOfLine
			txtInfo.AppendText(strResult) + EndOfLine
	end
	
	locator = Nil
	
	Exception err As oleexception
			msgbox err.message[/code]

Change IP address(static to DHCP):

[code] // WMI Win32_NetworkAdapterConfiguration
//
//
//https://msdn.microsoft.com/en-us/library/aa394217%28v=vs.85%29.aspx

	Dim locator, objWMIService, objNetAdapters, objProperty As OLEOBJECT
	Dim nobjs As Integer
	
	//  Connect to WMI
	locator = New oleObject("WbemScripting.SWbemlocator", True)
	
	Dim wmiServiceParams(0) As Variant
	wmiServiceParams(0) = "winmgmts:\\\\.\\root\\cimv2"
	
	Dim strResult As String
	Dim strSelect As String
	Dim lngEnable As Int32
	
	objWMIService = locator.invoke("ConnectServer", wmiServiceParams)
	strSelect = "Select * from Win32_NetworkAdapterConfiguration where Index="+strIdx
	objNetAdapters = objWMIService.ExecQuery(strSelect)
	
	objProperty = objNetAdapters.ItemIndex(0)
	
	lngEnable = objProperty.EnableDHCP()
	strResult = GetResult(lngEnable)
	txtInfo.AppendText("DHCP IP Result: " + str(lngEnable)) + EndOfLine
	txtInfo.AppendText(strResult) + EndOfLine
	
	lngEnable = objProperty.SetDNSServerSearchOrder(nil)
	strResult = GetResult(lngEnable)
	txtInfo.AppendText("DHCP DNS Result: " + str(lngEnable)) + EndOfLine
	txtInfo.AppendText(strResult) + EndOfLine
	
	locator = Nil

            Exception err As oleexception
	msgbox err.message[/code]

strIdx is the adapter index which you can get like this:

strIdx = objProperty.Value("Index")

:slight_smile:

[quote=161913:@Christian Schmitz]if you need an alternative, maybe check NetworkInterfaceMBS class?
http://www.monkeybreadsoftware.net/class-networkinterfacembs.shtml

to get current IP of computer, I normally use local address property of socket classes.[/quote]
Is there a cross-platform version of this plugin?

Sorry, no.
See WindowsEthernetMBS class for Windows.