{"id":50795324,"url":"https://github.com/daboss2003/react-native-local-network-info","last_synced_at":"2026-06-12T14:01:37.925Z","repository":{"id":364037934,"uuid":"1265470713","full_name":"daboss2003/react-native-local-network-info","owner":"daboss2003","description":"Read a React Native device's own local IPv4 address and whether it is connected to WiFi or acting as a hotspot host, with live network-change events. Built with the Expo Modules API; works in bare React Native and Expo.","archived":false,"fork":false,"pushed_at":"2026-06-11T10:42:24.000Z","size":90,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-11T12:15:38.879Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daboss2003.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-10T20:02:15.000Z","updated_at":"2026-06-11T10:42:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/daboss2003/react-native-local-network-info","commit_stats":null,"previous_names":["daboss2003/react-native-local-network-info"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/daboss2003/react-native-local-network-info","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboss2003%2Freact-native-local-network-info","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboss2003%2Freact-native-local-network-info/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboss2003%2Freact-native-local-network-info/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboss2003%2Freact-native-local-network-info/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daboss2003","download_url":"https://codeload.github.com/daboss2003/react-native-local-network-info/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboss2003%2Freact-native-local-network-info/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34247461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-12T14:01:37.082Z","updated_at":"2026-06-12T14:01:37.920Z","avatar_url":"https://github.com/daboss2003.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-local-network-info\n\nRead a React Native device's **own local IPv4 address** and whether it's **connected to WiFi** or **acting as a hotspot host** — with **live network-change events**.\n\n\u003e ℹ️ This library only reads **your own device's** network interfaces. It does **not** scan, probe, or connect to any other device on the network, and it needs no location permission.\n\nBuilt with the [Expo Modules API](https://docs.expo.dev/modules/overview/), so it works in **both bare React Native and Expo** apps and supports the New Architecture out of the box.\n\n## Why\n\n`expo-network` / `WifiManager.getConnectionInfo()` only return the **WiFi station** IP — they report `0.0.0.0` when the device is the hotspot host. This module reads the device's network interfaces directly, so it returns a usable LAN IP whether the device is a WiFi client **or** the hotspot, and tells you which.\n\n## Features\n\n- ✅ Device's own **local IPv4** on the active LAN interface.\n- ✅ **Role**: `wifi`, `hotspot`, or `none`.\n- ✅ **WiFi takes precedence** when both WiFi and hotspot are active at once.\n- ✅ **Hotspot host** detection that handles Android 11+'s **randomized** SoftAP subnet (reads the real interface IP — never hardcodes `192.168.43.1`).\n- ✅ **Predicted client IP range** when the device is a hotspot (iOS: fixed `172.20.10.2–.14`; Android: derived from the live subnet).\n- ✅ **Live listener** that re-fires on every connectivity / WiFi / hotspot change.\n- ✅ A `useLocalIp()` React hook.\n- ✅ No location permission required.\n\n## Installation\n\n```sh\nnpm install react-native-local-network-info\n```\n\n\u003e **Bare React Native:** you must also have the `expo` package installed so Expo Modules autolinking works. If you don't yet:\n\u003e ```sh\n\u003e npx install-expo-modules@latest\n\u003e ```\n\u003e Then `cd ios \u0026\u0026 pod install`. Expo apps need no extra steps.\n\n### Requirements\n\n| | Minimum |\n| --- | --- |\n| Expo SDK | 54+ (New Architecture) |\n| iOS | 15.1 |\n| Android | API 24 (Android 7.0) |\n\n### Permissions\n\nAndroid permissions are merged automatically via the module's manifest:\n\n- `ACCESS_NETWORK_STATE` — for the change listener \u0026 station gateway.\n- `ACCESS_WIFI_STATE` — for the DHCP gateway fallback.\n\nNo `ACCESS_FINE_LOCATION` and no iOS `Info.plist` keys are needed — the module only reads its **own** interfaces (it never connects to or scans other devices).\n\n## Usage\n\n```ts\nimport {\n  getLocalIp,\n  addNetworkChangeListener,\n  useLocalIp,\n} from 'react-native-local-network-info';\n\n// One-shot read\nconst info = await getLocalIp();\nconsole.log(info.ip, info.role); // e.g. \"192.168.1.42\" \"wifi\"\n\n// Live updates\nconst sub = addNetworkChangeListener((info) =\u003e {\n  console.log('network changed →', info.role, info.ip);\n});\n// later: sub.remove();\n```\n\n### React hook\n\n```tsx\nimport { useLocalIp } from 'react-native-local-network-info';\n\nfunction Status() {\n  const info = useLocalIp(); // null until first snapshot, then live\n  if (!info) return \u003cText\u003eDetecting…\u003c/Text\u003e;\n  return (\n    \u003cText\u003e\n      {info.role === 'hotspot' ? 'Hosting hotspot at' : 'Local IP'}: {info.ip}\n    \u003c/Text\u003e\n  );\n}\n```\n\n## API\n\n### `getLocalIp(): Promise\u003cLocalIpInfo\u003e`\n\nCaptures the current snapshot.\n\n### `addNetworkChangeListener(cb): EventSubscription`\n\nSubscribes to changes. Call `.remove()` on the returned subscription to unsubscribe.\n\n### `getAllInterfaces(): Promise\u003cNetworkInterfaceInfo[]\u003e`\n\nEvery up, non-loopback IPv4 interface with a best-effort role — handy for debugging unusual devices.\n\n### `useLocalIp(): LocalIpInfo | null`\n\nHook returning the latest snapshot, kept live and auto-cleaned on unmount.\n\n### `LocalIpInfo`\n\n```ts\ninterface LocalIpInfo {\n  ip: string | null;                 // device's own local IPv4 (wifi first, then hotspot)\n  role: 'wifi' | 'hotspot' | 'none'; // wifi wins when both are active\n  isWifiConnected: boolean;\n  isHotspotHost: boolean;\n  interfaceName: string | null;      // \"en0\" | \"wlan0\" | \"bridge100\" | \"ap0\" | ...\n  netmask: string | null;            // \"255.255.255.0\"\n  gateway: string | null;            // see notes below\n  predictedClientRange: { first: string; last: string } | null; // hotspot only\n  platform: 'ios' | 'android' | 'web';\n  timestamp: number;                 // epoch ms\n}\n```\n\n## How detection works\n\n| | iOS | Android |\n| --- | --- | --- |\n| Enumeration | `getifaddrs(3)` | `java.net.NetworkInterface` |\n| WiFi station | `en0` | the interface `ConnectivityManager` reports for the `TRANSPORT_WIFI` network (usually `wlan0`) |\n| Hotspot host | `bridge*` @ `172.20.10.1/28` | any WiFi-family interface (`wlan*`/`ap*`/`swlan*`/`softap*`) that is **not** the confirmed station — reads its live IP |\n| Cellular (ignored for LAN IP) | `pdp_ip0` | `rmnet*` / `ccmni*` |\n| Change events | `NWPathMonitor` | `registerDefaultNetworkCallback` + `WIFI_AP_STATE_CHANGED` |\n| Station gateway | derived from subnet (heuristic) | `LinkProperties` default route (real) |\n\n**Precedence:** if a WiFi-station IP exists it is returned with `role: 'wifi'`; otherwise the hotspot-host IP is returned with `role: 'hotspot'`; otherwise `role: 'none'` with `ip: null`.\n\n## Platform notes \u0026 limitations\n\n- **iOS station gateway is a heuristic** (first host of the subnet). Apple exposes no public default-gateway API; the WiFi IP, netmask, and role are accurate.\n- **iOS hotspot change events:** `NWPathMonitor` reliably reports WiFi/cellular changes, but toggling Personal Hotspot while the default path is unchanged may not fire an event. Call `getLocalIp()` to force a fresh read when you need certainty.\n- **Android hotspot vs. station** is resolved by asking `ConnectivityManager` which interface carries the real `TRANSPORT_WIFI` (station) network, then treating any *other* WiFi-family interface with an IP as the hotspot. This correctly handles phones that host the SoftAP on `wlan0` itself (not just `ap0`/`swlan0`), and devices running WiFi + hotspot concurrently. Use `getAllInterfaces()` to inspect an unusual device.\n- **Web** returns `role: 'none'` / `ip: null` — browsers don't expose the LAN IP.\n- iOS interface-name → role mapping is a documented **heuristic** (Apple exposes no public role API); the hotspot-host `172.20.10.1`/`255.255.255.240` fingerprint and `NetworkInterface` reads are the reliable signals.\n\n## Example app\n\n```sh\ncd example\nnpm install\nnpx expo prebuild        # generates ios/ and android/\nnpx expo run:ios         # or: npx expo run:android\n```\n\nThen toggle WiFi / your hotspot in Settings and watch the values update live.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaboss2003%2Freact-native-local-network-info","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaboss2003%2Freact-native-local-network-info","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaboss2003%2Freact-native-local-network-info/lists"}