Class

NetworkInterface


Description

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

Properties

Name

Type

Read-Only

Shared

IPAddress

String

Loopback

NetworkInterface

MACAddress

String

Name

String

SubnetMask

String

Property descriptions


NetworkInterface.IPAddress

IPAddress As String

The IP address of the user's computer.

This property is read-only.

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 Opening event handler is:

Var index As Integer

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

The SelectionChanged event handler for the PopupMenu is this:

Var n As NetworkInterface

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

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

NetworkInterface.Loopback

Loopback As NetworkInterface

Represents the loopback network interface. This interface can be used with sockets to make them listen only for connections originating on the same machine (similar to IPCSockets).

This property is read-only.

This property is shared.

Var loopback As NetworkInterface = NetworkInterface.Loopback

NetworkInterface.MACAddress

MACAddress As String

The Mac address of the user's computer.

This property is read-only.

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 Opening event handler is:

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

The SelectionChanged event handler for the PopupMenu is this:

Var n As NetworkInterface

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

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

NetworkInterface.Name

Name As String

The name of the interface as provided by the OS.

This property is read-only.


NetworkInterface.SubnetMask

SubnetMask As String

The subnet mask of the user's computer.

This property is read-only.

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 Opening event handler is:

Var index As Integer

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

The SelectionChanged event handler for the PopupMenu is this:

Var n As NetworkInterface

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

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

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.

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 Opening event handler is:

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

The SelectionChanged 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.Text = n.MACAddress
' Get the IP Address
IPAddressField.Text = n.IPAddress
' Get the Subnet Mask
SubnetMaskField.Text = n.SubnetMask

Compatibility

All project types on all supported operating systems.

See also

System module; SocketCore, TCPSocket classes.