Expo

Documentation

Network

This module provides useful information about the device's network such as its IP address, MAC address, and airplane mode status.
Platform Compatibility
Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

For managed apps, you'll need to run expo install expo-network. To use it in a bare React Native app, follow its installation instructions.

import * as Network from 'expo-network';

Gets the device's current network connection state.
On web, navigator.connection.type is not available on browsers. So if there is an active network connection, the field type returns NetworkStateType.UNKNOWN. Otherwise, it returns NetworkStateType.NONE.

A Promise that resolves to an object with the following fields:
  • type (NetworkStateType) -- a NetworkStateType enum value that represents the current network connection type.
  • isConnected (boolean) -- if there is an active network connection. Note that this does not mean that internet is reachable. This field is false if the type is either Network.NetworkStateType.NONE or Network.NetworkStateType.UNKNOWN, true otherwise.
  • isInternetReachable (boolean) -- if the internet is reachable with the currently active network connection. On Android, this depends on NetInfo.isConnected() (API level < 29) or ConnectivityManager.getActiveNetwork() (API level >= 29). On iOS, this value will always be the same as isConnected.
Examples
await Network.getNetworkStateAsync();
// {
//   type: NetworkStateType.CELLULAR,
//   isConnected: true,
//   isInternetReachable: true,
// }

Gets the device's current IPv4 address.
On web, this method uses Ipify Api to get public ip address of current device via http request.

A Promise that resolves to a string of the current IP address of the device's main network interface. Can only be IPv4 address.
Examples
await Network.getIpAddressAsync();
// "92.168.32.44"

Gets the specified network interface's Mac address. On Android, it requires android.permission.ACCESS_WIFI_STATE permission to access available network interfaces.

  • interfaceName (string) -- A string representing interface name (eth0, wlan0) or null, meaning the method should fetch the MAC address of the first available interface. (On iOS this argument is ignored.) If undefined interface name passed in, the method would reject the promise with corresponding message.

A Promise that resolves to a string of the network adapter MAC address or null if there's no such address matching the interface. On web, the Promise resolves to null.
Note from Apple: In iOS 7 and later, if you ask for the MAC address of an iOS device, the system returns the value "02:00:00:00:00:00".
If you need to identify the device, use the getIosIdForVendorAsync() method of the expo-application unimodule instead.
Examples
await Network.getMacAddressAsync();
// "E5:12:D8:E5:69:97"

Android only. Tells if the device is in airplane mode.

Returns a Promise that resolves to the boolean value for whether the device is in airplane mode or not.
Examples
await Network.isAirplaneModeEnabledAsync();
// false

An enum of the different types of devices supported by Expo, with these values:
  • NONE -- no active network connection detected.
  • UNKNOWN -- the connection type could not be determined.
  • CELLULAR -- active network connection over mobile data or DUN-specific mobile connection when setting an upstream connection for tethering.
  • WIFI -- active network connection over Wifi.
  • BLUETOOTH -- active network connection over Bluetooth.
  • ETHERNET -- active network connection over Ethernet.
  • WIMAX -- active network connection over Wimax.
  • VPN -- active network connection over VPN.
  • OTHER -- active network connection over other network connection types.

CodeDescription
ERR_NETWORK_IP_ADDRESSOn Android, there may be an unknown Wifi host when trying to access WifiManager in getIpAddressAsync. On iOS, no network interfaces could be retrieved.
ERR_NETWORK_UNDEFINED_INTERFACEAn undefined interfaceName was passed as an argument in getMacAddressAsync.
ERR_NETWORK_SOCKET_EXCEPTIONAn error was encountered in creating or accessing the socket in getMacAddressAsync.
ERR_NETWORK_INVALID_PERMISSION_INTERNETThere are invalid permissions for android.permission.ACCESS_WIFI_STATE in getMacAddressAsync.
ERR_NETWORK_NO_ACCESS_NETWORKINFOUnable to access network information