Class

# NetworkInterface

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

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

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                      | Type                             | Read-Only | Shared |
|-------------------------------------------|----------------------------------|-----------|--------|
| `IPAddress<networkinterface.ipaddress>`   | `String</api/data_types/string>` | ✓         |        |
| `Loopback<networkinterface.loopback>`     | NetworkInterface                 | ✓         | ✓      |
| `MACAddress<networkinterface.macaddress>` | `String</api/data_types/string>` | ✓         |        |
| `Name<networkinterface.name>`             | `String</api/data_types/string>` | ✓         |        |
| `SubnetMask<networkinterface.subnetmask>` | `String</api/data_types/string>` | ✓         |        |

## Property descriptions

<div id="networkinterface.ipaddress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NetworkInterface.IPAddress

**IPAddress** As `String</api/data_types/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</api/user_interface/desktop/desktoppopupmenu>`. The user then selects the desired network interface and the values are displayed in `TextFields</api/user_interface/desktop/desktoptextfield>`.
>
> The `PopupMenu's</api/user_interface/desktop/desktoppopupmenu>` Opening event handler is:
>
> ``` xojo
> For index As Integer = 0 To System.NetworkInterfaceCount - 1
>   PopupMenu1.AddRow(index.ToString)
> Next
> ```
>
> The SelectionChanged event handler for the `PopupMenu</api/user_interface/desktop/desktoppopupmenu>` is this:
>
> ``` xojo
> 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
> ```

<div id="networkinterface.loopback">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

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</api/language/shared>`.
>
> ``` xojo
> Var loopback As NetworkInterface = NetworkInterface.Loopback
> ```

<div id="networkinterface.macaddress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NetworkInterface.MACAddress

**MACAddress** As `String</api/data_types/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</api/user_interface/desktop/desktoppopupmenu>`. The user then selects the desired network interface and the values are displayed in `TextFields</api/user_interface/desktop/desktoptextfield>`.
>
> The `PopupMenu's</api/user_interface/desktop/desktoppopupmenu>` Opening event handler is:
>
> ``` xojo
> For index As Integer = 0 To System.NetworkInterfaceCount - 1
>   PopupMenu1.AddRow(index.ToString)
> Next
> ```
>
> The SelectionChanged event handler for the `PopupMenu</api/user_interface/desktop/desktoppopupmenu>` is this:
>
> ``` xojo
> 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
> ```

<div id="networkinterface.name">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NetworkInterface.Name

**Name** As `String</api/data_types/string>`

> The name of the interface as provided by the OS.
>
> This property is read-only.

<div id="networkinterface.subnetmask">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

NetworkInterface.SubnetMask

**SubnetMask** As `String</api/data_types/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</api/user_interface/desktop/desktoppopupmenu>`. The user then selects the desired network interface and the values are displayed in `TextFields</api/user_interface/desktop/desktoptextfield>`.
>
> The `PopupMenu's</api/user_interface/desktop/desktoppopupmenu>` Opening event handler is:
>
> ``` xojo
> For index As Integer = 0 To System.NetworkInterfaceCount - 1
>   PopupMenu1.AddRow(index.ToString)
> Next
> ```
>
> The SelectionChanged event handler for the `PopupMenu</api/user_interface/desktop/desktoppopupmenu>` is this:
>
> ``` xojo
> 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</api/os/system>` module to instantiate the <span class="title-ref">NetworkInterface</span> 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</api/os/system>` module and assign the obtained interface object to the <span class="title-ref">NetworkInterface</span> property of the `SocketCore</api/networking/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</api/user_interface/desktop/desktoppopupmenu>`. The user then selects the desired network interface and the values are displayed in `TextFields</api/user_interface/desktop/desktoptextfield>`.

The `PopupMenu's</api/user_interface/desktop/desktoppopupmenu>` Opening event handler is:

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The SelectionChanged event handler for the `PopupMenu</api/user_interface/desktop/desktoppopupmenu>` is this:

``` xojo
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

|                       |                               |
|-----------------------|-------------------------------|
| **Project Types**     | Console, Desktop, Mobile, Web |
| **Operating Systems** | iOS, Linux, macOS, Windows    |

<div class="seealso">

`System</api/os/system>` module; `SocketCore</api/networking/socketcore>`, `TCPSocket</api/networking/tcpsocket>` classes.

</div>
