System.NetworkInterface

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Method

System.NetworkInterface(index As Integer = -1) As NetworkInterface

New in 2019r2

Supported on Desktop, Web, Console.

Use the NetworkInterface object to obtain networking information about the user's computer.

Notes

Use the optional parameter to specify the network interface card. If Index is out of bounds, an OutOfBoundsException is raised. NetworkInterfaceCount gives you the number of network interfaces in the computer.

Sample Code

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(i.ToString)
Next

The SelectionChanged event handler for the PopupMenu is this:

Sub SelectionChanged()
If Me.SelectedRowIndex > -1 Then
// Get the NetworkInterface object for the selected item
Var iface As NetworkInterface = System.NetworkInterface(Me.SelectedRowIndex)
MacAddressField.Text = iface.MACAddress
IPAddressField.Text = iface.IPAddress
SubnetMaskField.Text = iface.SubnetMask
End If
End Sub