point-source / dart_ping

Multi-platform network ping utility for Dart
31 stars 14 forks source link

Can't ping an IP address when using mobile data on iOS16 #52

Open July250229 opened 1 year ago

July250229 commented 1 year ago

Hello, thank you for your excellent work.

But I found a bug that if you ping an IP address on iOS16 when using mobile data, you will get "unknownHost"

But you can ping a domain, it will work as normal.

point-source commented 1 year ago

Interesting. Is the IP you are pinging responding to pings on the open web when pinging from other platforms?

July250229 commented 1 year ago

Interesting. Is the IP you are pinging responding to pings on the open web when pinging from other platforms?

Yes, the ip addresses I tried to ping work well. And I tried to ping from my Mac, my Android. I also tried:

  1. Downloaded iSH to ping the same IP on my iOS 16 device, the ping worked well.
  2. Open a Personal Hotspot from my iPhone for another Android phone running the same program and it works well on my Android Phone.
  3. Ping on My MacOS.
  4. Ping on My MacOS under Personal Hotspot from my iPhone which is using mobile data.

After the comparison, I felt it just didn't work when you tried to ping an IP address directly on iOS16. (I'm not sure about iOS system under 16).

I tried to solve this problem, but I'm not familiar with Objective-C, have no idea about that.

Here is an example: IP: 13.35.27.1

if (Platform.isIOS) {
          String pingIp = ip;
          DartPingIOS.register();
          final ping = Ping(pingIp, count: 1, timeout: 1);
          var pingResult = 99999;
          await for (var event in ping.stream.timeout(const Duration(milliseconds: 5000))) {
            if (event.response != null && event.response!.time!.inMilliseconds < 1000 && event.response!.time!.inMilliseconds > 5) {
              print("pingResult: $ip ${event.response!.time!.inMilliseconds}");
              pingResult = event.response!.time!.inMilliseconds;
            }

            if (event.error != null) {
              print(event.error.toString());
            }
          }
          await ping.stop();
          return {"ip": ip, "ping": pingResult};

      }

On iOS16 mobile data, will get unknownHost error for every IP address.

point-source commented 1 year ago

Okay thanks for that. I'll look into it. Guessing it works in iOS simulator as well but just not on hardware?

July250229 commented 1 year ago

Okay thanks for that. I'll look into it. Guessing it works in iOS simulator as well but just not on hardware?

Yes, just made a test on iOS simulator and on my phone. On simulator it works well.

start:868894014 **<-this  is on real phone under WIFI**
2023-07-24 10:18:07.189768+1000 Runner[37426:3541767] flutter: pingResult: 13.35.27.1 201
stop:868894014
start:268237719 **<-this  is on real phone under mobile data**
2023-07-24 10:18:13.886103+1000 Runner[37426:3541767] flutter: unknownHost
2023-07-24 10:18:18.897617+1000 Runner[37426:3541767] [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: TimeoutException after 0:00:05.000000: No stream event
point-source commented 1 year ago

Sorry it took me so long to look at this. I didn't have any iOS devices with a mobile data plan. I have now attempted to reproduce this using an iPad Pro (3rd Gen) on Google Fi with wifi turned off. I was able to ping google.com, 1.1.1.1, and 13.35.27.1 successfully via the physical data sim card in the iPad. So at this time, I cannot reproduce this issue. Are you still having this problem?

July250229 commented 1 year ago

Sorry it took me so long to look at this. I didn't have any iOS devices with a mobile data plan. I have now attempted to reproduce this using an iPad Pro (3rd Gen) on Google Fi with wifi turned off. I was able to ping google.com, 1.1.1.1, and 13.35.27.1 successfully via the physical data sim card in the iPad. So at this time, I cannot reproduce this issue. Are you still having this problem?

Thank you for your reply. I made a test just now. Still got flutter: unknownHost error.

My device: iPhone 14 Pro Carrier: Telstra 5G in Australia

I can help to get logs if you can tell me how to catch useful logs for you.

As I met before, only on real phone and under mobile data will 100% meet this problem.