lontivero/Open.NAT

GetExternalIPAddress sometimes fail

leopreuss opened this issue · 3 comments

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.

Would you be able to share your solution?

@lucasmontec :

Would you be able to share your solution?

Here's mine : #100

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