Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Tracert for .NET MAUI Android finally done in .NET 7.0.3 #41

Closed
norton287 opened this issue Feb 16, 2023 · 12 comments
Closed

Fix for Tracert for .NET MAUI Android finally done in .NET 7.0.3 #41

norton287 opened this issue Feb 16, 2023 · 12 comments

Comments

@norton287
Copy link

They have finally put in a fix in .NET 7.0.3 for .NET MAUI Android for Ping that allows Tracert functionality on all devices.

You just have to modify the payload to be just this instead of the usual:

Array.Empty<byte>

Reference my Github issue here on the resolution: Issue

Could you allow this in your utility for Android then I could reimplement Tracert in my app again! This is good news!

But it still does not function on the emulator, only on real devices :(

John

@hekkaaa
Copy link
Owner

hekkaaa commented Feb 17, 2023

Hello @norton287 .
I'll see what i can do. I do not promise that it will be promptly resolved, because. I'm currently busy with another project.

@norton287
Copy link
Author

norton287 commented Feb 17, 2023 via email

@hekkaaa
Copy link
Owner

hekkaaa commented Mar 16, 2023

Hi @norton287 .
I read the bugfix from the developers several times and didn't quite understand what needs to be changed in the code.
For my part , I decided to test the code on MAUI .NET 7.
Everything works fine on the Windows platform as before, but I have problems on the Android emulator.

The error is as follows:
System.Exception: 'Unexpected error Unable to send custom ping payload. Run program under privileged user account or grant cap_net_raw capability using setcap(8).'

red line screen - launched under the account "Administrator".

Unfortunately I have no way to test on a real android device.
So far I have no ideas how to check the work of the code differently and to debug the code, and to do debugging.

image

@norton287
Copy link
Author

@hekkaaa Just set the payload to this:

Array.Empty<byte>

That should take care of the error but the emulators were stripped of the ability to do a ping -t so they will fail on a tracert. Normal ping will work though.

@norton287
Copy link
Author

norton287 commented Mar 16, 2023

@hekkaaa This is my workaround for now with Array payload as an example:

for (var i = 1; i <= 30; i++) { var reply = await new Ping().SendPingAsync(hostname, 5000, Array.Empty<byte>(), new PingOptions(i, true)); Debug.WriteLine($"Hop {i} IP: {reply.Address}"); InterHopsList.Add(new IHops() { Address = reply.Address }); if (reply.Status == IPStatus.Success) { // Stop tracing if ping is successful break; } }

Edit: It did not paste right for some reason

@hekkaaa hekkaaa linked a pull request Mar 16, 2023 that will close this issue
@hekkaaa
Copy link
Owner

hekkaaa commented Mar 16, 2023

@norton287
I added the recommended code to the test class TracerouteAndroidAsync. I hope I did everything right.
Can you add a test branch to your project and check if it helped?
test-android-fix
Or should I make a test release in nuget?

@norton287
Copy link
Author

@hekkaaa can you make a test nuget, it will be cleaner for me. I will install it and add the method to enable the tracert function and test it pretty fast.

@hekkaaa
Copy link
Owner

hekkaaa commented Mar 17, 2023

Hello @norton287.
I have a request for you. The current version of the library has advanced options for filling in arguments.
Can I ask you to run the following code in your application and see the result?
You may not have to make a separate class for Android.
There are also asynchronous methods in my library. You can use them if it's more convenient for you.

string hostname = "google.com";

Traceroute testTrac = new Traceroute();
IEnumerable<string> result = testTrac.GetIpTraceRoute(hostname, 4000, Array.Empty<byte>(), true, 1, 31);


IcmpRequestSender icmpRequestSender = new IcmpRequestSender();
PingReply res2 = icmpRequestSender.RequestIcmp(hostname, 4000, Array.Empty<byte>(), new PingOptions(2, true));

@norton287
Copy link
Author

@hekkaaa Excellent!! Both async and sync methods work great on Android! Again you have crafted a very wonderful and useful library that is essential in my toolkit!

@hekkaaa
Copy link
Owner

hekkaaa commented Mar 17, 2023

@norton287
I sometimes wonder at myself =)
So I understand that the issue has been resolved and we can close the task?

The manual for the tool can be found in my wiki.
I have described most of the methods of working with the library.
https://github.com/hekkaaa/NetObserver/wiki/Code-Manual-EN#public-ienumerablestring-getiptraceroutestring-hostname

@norton287
Copy link
Author

@hekkaaa Yes the task is complete and you have done an amazing job! Again, thank you for your work.

@hekkaaa
Copy link
Owner

hekkaaa commented Mar 17, 2023

Done

@hekkaaa hekkaaa closed this as completed Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants