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

uPnP discovery suddenly stopp working? #93

Open
ghost opened this issue Mar 6, 2019 · 10 comments
Open

uPnP discovery suddenly stopp working? #93

ghost opened this issue Mar 6, 2019 · 10 comments

Comments

@ghost
Copy link

ghost commented Mar 6, 2019

I am trying this but it does not always work:

using Rssdp;
using System;

namespace Discovery {
  class Program {
    static void Main(string[] args) {
      SearchForDevices();
      Console.ReadKey();
    }

    public static async void SearchForDevices() {
      using (var deviceLocator = new SsdpDeviceLocator()) {
        var foundDevices = await deviceLocator.SearchAsync();

        foreach (var foundDevice in foundDevices) {
          Console.WriteLine("Found " + foundDevice.Usn + " at " + foundDevice.DescriptionLocation.ToString());
        }
      }
    }
  }
}

It only shows output for the first 3 runs or so. Then for the rest of the day I get nothing. I have checked the firewall settings in windows and allowed UDP in and out on all ports. Still the same. Not even sure how to debug.

I am running this from .NET Core Console App, in Windows 10.

@marchewek
Copy link

UDP packets' delivery is not guaranteed - both broadcast message and response message can get lost in transfer.
In general discovery should be treated as convenience improvement and implemented side-by-side with manual configuration. And since discovery can be used as a vector of DDoS attacks, I'd also recommend implementing possibility to turn discovery completely off (enabling/disabling firewall rule; I'd additionally restrict the rule to local LAN).
If you want to see what is going on in the network, you could install any sniffing tool, e.g. Wireshark

@Yortw
Copy link
Owner

Yortw commented Sep 9, 2020

Also, I notice you have no error handling in your SearchForDevices method, and it's async void... so if an exception is occuring for some reason it's likely being swallowed silently. I would add a try catch in that method with some logging or a debugger break etc. and see if you get errors when it fails.

RSSDP does follow the SSDP spec and send most packets multiple times with a delay between each in order to 'work around' the occasional packet loss, but obviously that's still only best effort and doesn't guarantee anything. However since it works for you on the first ~3 runs and then fails, it seems a little odd to be accidental packet loss. Could be something deliberately dropping the packets due to some sort of security measure (after it sees X number of packets in a short time), but it's really hard to diagnose remotely without the ability to repro.

@Yortw
Copy link
Owner

Yortw commented Sep 9, 2020

Wireshark or something to what's happening on your network is probably the next step, as suggested by @marchewek

@winkmichael
Copy link

I've observed similar to @mohasi and numerous locations. In the end our solution was to run the query every 15 minutes via a cron job and build a MySQL data and then we display sorted by age. I tried compiling / running on Linux and Windows and found the results similar.

@Yortw
Copy link
Owner

Yortw commented Sep 9, 2020

That is odd, I wish I could reproduce so I had some chance of fixing it. I have it running in multiple networks and haven't seen this symptom.
Debugging with a network tool like Wireshark on a problem network might help, or trying to track down common factors/configurations across those problem networks.

@winkmichael
Copy link

I'll pull out my code in the next few days and do some sniffing! FYI, when I first observed it I just thought somehow this library wasn't doing as good as of a job at finding devices as my Ubiquti Edge Router or UPnP Analyser in the MS Store - I'd left the tool running via a 1 minute cronjob piping to file and found that with time it would get the same results as the other tools.

I will post back once I've done some additional digging.

@Yortw
Copy link
Owner

Yortw commented Sep 9, 2020

Is it possible those other tools use a larger wait time on the search command? If you're only waiting say 1 second for the search and some devices take longer than that to respond, those responses will get dropped. If those other systems are waiting 5 seconds on each search, they might drop fewer responses. Maybe.

Just spitballing ideas here.

@winkmichael
Copy link

Yes, good idea. I just did a super unscientific test and ran the UPNP discovery on my Ubiquiti, without knowing how the thing works, two observations; 1. Nothing appears in the list for at least 15 - 20 seconds, 2. The list of devices found populates over a several minute period.

@DeenAbd
Copy link

DeenAbd commented Feb 12, 2021

I have the same problem with V4.0.4, I don't think it is a timing problem because I left the program running over night. I still can't find a solution.

@wartek69
Copy link

wartek69 commented May 4, 2023

Anyone found a solution for this problem? Same issue here

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

No branches or pull requests

5 participants