In node we would use require('os')
but we cannot do such thing on react native. Any ideas?
There's a ReactNative library for getting information about the devices network:
react-native-network-info
// require module
var NetworkInfo = require('react-native-network-info');
// Get Local IP
NetworkInfo.getIPAddress(ip => {
console.log(ip);
});
import publicIP from 'react-native-public-ip';
publicIP()
.then(ip => {
console.log(ip);
// '47.122.71.234'
})
.catch(error => {
console.log(error);
// 'Unable to get IP address.'
});
For more info: https://www.npmjs.com/package/react-native-public-ip
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With