Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

GetExternalIPAddress sometimes fail #95

Open
leopreuss opened this issue Mar 31, 2020 · 3 comments
Open

GetExternalIPAddress sometimes fail #95

leopreuss opened this issue Mar 31, 2020 · 3 comments
Labels

Comments

@leopreuss
Copy link

When searching for NAT devices (DiscoverDeviceAsync method) results can be out of order. That is, sometimes IPv6 device is returned instead of IPv4.

This happens because DiscoverDeviceAsync method always return the first element in devices found list. But the list order is unpredictable since you cannot know which device will respond first during discovery. So, GetExternalIPAddress fails on some Routers cause it is trying to get IPv6 Address that is not currently active on router's WAN interface. In this case, other methods like CreatePortMapAsync or DeletePortMapAsync do not work as well.

I solved this by extending NatDiscoverer class and creating a method that accepts another argument that acts as a filter. This new method filters the result by IP's AddressFamily. Therefore, I always retrieve the right device and no problems ocurrs when getting external IP address.

I think it would be easier if NatDevice class or UpnpNatDevice contained public fields that identify which type of device it is, like IP family, service type, and so on.

@lucasmontec
Copy link

Would you be able to share your solution?

@manutoo
Copy link

manutoo commented Jan 17, 2021

@lucasmontec :

Would you be able to share your solution?

Here's mine : #100

@lontivero
Copy link
Owner

Thanks for reporting this and for providing a solution. I hope to be able to work on it next month.

@lontivero lontivero added the bug label Jan 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants