NetworkInterface

From Xojo Documentation

Module

Used to obtain information about the computer’s network interface.

Properties
IPAddress fa-lock-32.png MacAddress fa-lock-32.png SubnetMask fa-lock-32.png


Shared Properties
Loopback fa-lock-32.png

Notes

Use the GetNetworkInterface method of the System module to instantiate the NetworkInterface object. See the example.

Multiple network interfaces are supported for Windows, macOS, and Linux. This allows you to write applications that can bind to different network interface cards on a user's machine. You can use this to write tunneling applications, for example.

To see what interfaces are installed on the user’s machine, use the GetNetworkInterface method of the System module and assign the obtained interface object to the NetworkInterface property of the SocketCore class. When you do so, the socket will bind to that network interface.

Examples

The following simple example displays the IP address, Subnet mask, and Mac address for the selected network interface. At start-up, the application detects all the network interfaces installed on the user's computer and loads them into a PopupMenu. The user then selects the desired network interface and the values are displayed in TextFields.

The PopupMenu's Open event handler is:

For i As Integer = 0 To System.NetworkInterfaceCount - 1
PopupMenu1.AddRow(Str(i))
Next

The Change event handler for the PopupMenu is this:

Var n As NetworkInterface

// Get the NetworkInterface object for the selected item
n = System.NetworkInterface(Me.SelectedRowIndex)

// Get the MAC Address
MacAddressField.Value = n.MACAddress
// Get the IP Address
IPAddressField.Value = n.IPAddress
// Get the Subnet Mask
SubnetMaskField.Value = n.SubnetMask

See Also

System module; SocketCore, TCPSocket classes.]