Tulsi Ram
Tulsi Ram

Reputation: 324

Expo get device local ip-address

I'm developing a mobile application using Expo framework(react native).

I need to find the device's local IP address in order to connect to a specific device on the intranet.

Please guide me through this task.

Thanks

Upvotes: 5

Views: 6044

Answers (2)

Lonare
Lonare

Reputation: 4703

You can use Expo Network.getIpAddressAsync() which returns a Promise, so you need to resolve it first.

Here is an example:

import * as Network from 'expo-network';

const ipAlert = async () => {
  const ip = await Network.getIpAddressAsync()
  alert(ip);
};

ipAlert();

Upvotes: 3

Medet Tleukabiluly
Medet Tleukabiluly

Reputation: 11950

https://docs.expo.io/versions/latest/sdk/network/#networkgetipaddressasync

await Network.getIpAddressAsync();
// "92.168.32.44

Upvotes: 3

Related Questions