Open internelp opened 2 years ago
I added the ttl option. Please check it out.
Hi zuvola, I think there are still some problems.
This is my code:
try {
debugPrint(DateTime.now().toIso8601String());
final ping = Ping(
'www.google.com',
count: 1,
timeout: 10,
interval: 1,
ipv6: false,
ttl: 1,
);
ping.stream.listen((PingData event) {
print(">>>>>>>${DateTime.now().toIso8601String()}");
print("response: ${event.response.toString()}");
print("response time: ${event.response?.time}");
print("response ip: ${event.response?.ip}");
print("error: ${event.error}");
print("summary: ${event.summary.toString()}");
print("<<<<<<<");
});
} catch (e) {
print('error $e');
}
And this is the output:
flutter: 2022-04-12T16:39:37.860499
start:131873042
flutter: >>>>>>>2022-04-12T16:39:47.950086
flutter: response: PingResponse(seq:0, ip:199.59.148.229, ttl:1, time:0.0 ms)
flutter: response time: 0:00:00.000000
flutter: response ip: 199.59.148.229
flutter: error: PingError.requestTimedOut
flutter: summary: null
flutter: <<<<<<<
flutter: >>>>>>>2022-04-12T16:39:47.954159
flutter: response: null
flutter: response time: null
flutter: response ip: null
flutter: error: null
flutter: summary: PingSummary(transmitted:1, received:0, time:10001 ms)
flutter: <<<<<<<
This is macos ping output:
feng@Fengs-iMac ~ % ping www.google.com -m 1 -t 2
PING www.google.com (199.59.148.229): 56 data bytes
36 bytes from 10.0.54.254: Time to live exceeded
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
4 5 00 5400 f96c 0 0000 01 01 235f 10.0.54.189 199.59.148.229
Request timeout for icmp_seq 0
36 bytes from 10.0.54.254: Time to live exceeded
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
4 5 00 5400 60fc 0 0000 01 01 bbcf 10.0.54.189 199.59.148.229
--- www.google.com ping statistics ---
2 packets transmitted, 0 packets received, 100.0% packet loss
My ip is 10.0.54.2
;
My network gateway ip is 10.0.54.254
;
My ping destination domin is www.google.com
and it's ip is 199.59.148.229
;
The route map is like below: 10.0.54.2 <--> 10.0.54.254(first router) <--> 22.33.44.55(second router) <--> Several routers <--> 199.59.148.229(google.com's ip)
When I set the outgoing ttl is 1
, my gateway (10.0.54.254) will reponse me the Time to live exceeded
error, and the reponse ip will be 10.0.54.254
.
If I set the ttl is 2
, the reponse will be 22.33.44.55(second router)
.
Only if the TTL value is greater than the number of routers I sent to google.com will google.com return it directly.
But flutter_icmp_ping's reponse is not like this.
My guess is that you may have overlooked reponses from non-target addresses.
Please check, thanks.
The correct response would be something like this
flutter: >>>>>>>2022-04-12T16:39:47.950086
flutter: response: PingResponse(seq:0, ip:199.59.148.229, ttl:1, time:0.0 ms)
flutter: response time: 0:00:00.012000
flutter: response ip: `10.0.54.254`
flutter: error: `PingError.timeToLiveExceeded`
flutter: summary: null
flutter: <<<<<<<
Thank you for your report. I am using a library called GBPing internally, and it seems to be the problem here. This library is out of development, so it looks like I'll have to fix it myself. I will take a look at it when I have time. Of course, PR is very welcome.
https://developer.apple.com/library/archive/samplecode/SimplePing/Introduction/Intro.html
Apple have samplecode named "SimplePing", but I'm not good at using OC for development. Maybe you can refer to or replace GBPing.
Adding ICMP Protocol to flutter is a great work. Thank you for your efforts.
Thanks for the information. It would certainly be best if we could replace the library.
Any updates?
On macOS , we can use
-m ttl
to set this variable, like this:On Windows, we can use
-i ttl
to set this variable, like this: