You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run example project and take a look to gatewayIP returned
The plugin return ip of dhcp host and not the network gateway !
You can see on plugin code:
fun getGatewayIPAddress(): String? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val linkAddresses = connectivityManager?.getLinkProperties(connectivityManager.activeNetwork)
val dhcpServer = linkAddresses?.dhcpServerAddress?.hostAddress
dhcpServer
} else {
@Suppress("DEPRECATION")
val dhcpInfo = wifiManager.dhcpInfo
val gatewayIPInt = dhcpInfo?.gateway
gatewayIPInt?.let { formatIPAddress(it) }
}
}
Code Sample
I'm using a simplified version of plugin example:// Copyright 2017 The Chromium Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.// ignore_for_file: public_member_api_docsimport 'dart:async';import 'dart:developer' as developer;import 'dart:io';import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:network_info_plus/network_info_plus.dart';// Sets a platform override for desktop to avoid exceptions. See// https://flutter.dev/desktop#target-platform-override for more info.void _enablePlatformOverrideForDesktop() { if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) { debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia; }}void main() { _enablePlatformOverrideForDesktop(); runApp(const MyApp());}class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'FlutterDemo', theme: ThemeData( useMaterial3: true, colorSchemeSeed: const Color(0x9f4376f8), ), home: const MyHomePage(title: 'FlutterDemoHomePage'), ); }}class MyHomePage extends StatefulWidget { const MyHomePage({super.key, this.title}); final String? title; @override State<MyHomePage> createState() => _MyHomePageState();}class _MyHomePageState extends State<MyHomePage> { String _connectionStatus = 'Unknown'; final NetworkInfo _networkInfo = NetworkInfo(); @override void initState() { super.initState(); _initNetworkInfo(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('NetworkInfoPlus example'), elevation: 4, ), body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ const Text( 'Network info', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 16), Text(_connectionStatus), ], )), ); } Future<void> _initNetworkInfo() async { String? wifiName, wifiSSID, wifiBSSID, wifiIP, wifiIPv6, wifiGatewayIP, // prende ip sbagliato ! .200 ?? è un dns wifiBroadcast, wifiSubmask; /* final _initNetworkInfo = NetworkInfo(); String? wifiSSID; String? wifiBSSID; String? wifiIP; String? wifiGatewayIP; */ try { if (Platform.isAndroid) { wifiSSID = await _networkInfo.getWifiName(); wifiBSSID = await _networkInfo.getWifiBSSID(); wifiIP = await _networkInfo.getWifiIP(); wifiGatewayIP = await _networkInfo.getWifiGatewayIP(); } else if (Platform.isIOS) { final LocationAuthorizationStatus status = await _networkInfo.getLocationServiceAuthorization(); if (status == LocationAuthorizationStatus.authorizedAlways || status == LocationAuthorizationStatus.authorizedWhenInUse) { wifiSSID = await _networkInfo.getWifiName(); wifiBSSID = await _networkInfo.getWifiBSSID(); wifiIP = await _networkInfo.getWifiIP(); } else { wifiSSID = await _networkInfo.getWifiName(); wifiBSSID = await _networkInfo.getWifiBSSID(); wifiIP = await _networkInfo.getWifiIP(); } } else { // not supported developer.log('NOT supported'); } developer.log("raw bssid: $wifiSSID"); } on PlatformException catch (e) { developer.log('Failed to getWifiName', error: e); wifiName = 'Failed to getWifiName'; } setState(() { _connectionStatus = 'WifiName: $wifiSSID\n' 'WifiBSSID: $wifiBSSID\n' 'WifiIPv4: $wifiIP\n' //'WifiIPv6: $wifiIPv6\n' //'WifiBroadcast: $wifiBroadcast\n' 'WifiGateway: $wifiGatewayIP\n'; //'WifiSubmask: $wifiSubmask\n'; }); }}
Logs
Log is too long for github but i published here:
https://drive.google.com/file/d/1-yY8MVMEmSe-N_Z4Fbsrc6VoYDxYQHsO/view?usp=sharing
Flutter Doctor
[✓] Flutter (Channel stable, 3.16.5, on macOS 14.2.1 23C71 darwin-arm64, locale it-IT)
• Flutter version 3.16.5 on channel stable at /Users/mauro/fvm/versions/3.16.5
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 78666c8dc5 (8 giorni fa), 2023-12-19 16:14:14 -0800
• Engine revision 3f3e560236
• Dart version 3.2.3
• DevTools version 2.28.4
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/mauro/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_SDK_ROOT = /Users/mauro/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15C65
• CocoaPods version 1.14.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
[✓] VS Code (version 1.85.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.80.0
[✓] Connected device (5 available)
• Pixel 8 (mobile) • 39191FDJH00EBY • android-arm64 • Android 14 (API 34)
• iPhoneMM (mobile) • 00008120-001E09CC119B401E • ios • iOS 17.2.1 21C66
• iPhone 15 Pro Max iOS 17.2 (mobile) • 2B941DD0-098F-49D2-9F89-B59F188C20D3 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.2.1 23C71 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 120.0.6099.129
[✓] Network resources
• All expected network resources are available.
• No issues found!
Checklist before submitting a bug
I searched issues in this repository and couldn't find such bug/problem
I Google'd a solution and I couldn't find it
I searched on StackOverflow for a solution and I couldn't find it
I read the README.md file of the plugin
I'm using the latest version of the plugin
All dependencies are up to date with flutter pub upgrade
I did a flutter clean
I tried running the example project
The text was updated successfully, but these errors were encountered:
Hi @blondie63, I tested the code against Android versions 10, 12, and 14 but got the actual wifi gateway IP address as expected. I'm not getting any wrong IP address you have mentioned. Please check again, and let us know if everything is not okay.
Platform
Android 14
Plugin
network_info_plus
Version
4.1.0
Flutter SDK
3.16.5
Steps to reproduce
Run example project and take a look to gatewayIP returned
The plugin return ip of dhcp host and not the network gateway !
You can see on plugin code:
fun getGatewayIPAddress(): String? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val linkAddresses = connectivityManager?.getLinkProperties(connectivityManager.activeNetwork)
val dhcpServer = linkAddresses?.dhcpServerAddress?.hostAddress
Code Sample
Logs
Flutter Doctor
Checklist before submitting a bug
flutter pub upgrade
flutter clean
The text was updated successfully, but these errors were encountered: