Coder Social home page Coder Social logo

onvif-discovery's Introduction

Onvif Discovery

NuGet version (OnvifDiscovery) Build Status Quality Gate Status Coverage Code Smells

OnvifDiscovery is a simple cross-platform .NET library to discover ONVIF compliant devices.

Getting started

OnvifDiscovery sends a probe message to all available network interfaces and waits the timeout specified in order to get the list of discovered onvif devices that replied to the probe message.

To use the library install and add a reference of the OnvifDiscovery nuget package, then call the discover method like the following sample:

// add the using
using OnvifDiscovery;

// Create a Discovery instance
var onvifDiscovery = new Discovery ();

// Call the asynchronous method DiscoverAsync that returns IAsyncEnumerable
// with a timeout of 1 second
await foreach (var device in discovery.DiscoverAsync(1, cancellationToken))
{
    // New device discovered
}

Finally, you can also use the DiscoverAsync method by passing a ChannelWriter<DiscoveryDevice>, the method will write to the channel devices as soon as they are discovered:

// add the using
using OnvifDiscovery;

// Create a Discovery instance
var onvifDiscovery = new Discovery ();

// You can call Discover with a ChannelWriter and CancellationToken
CancellationTokenSource cancellation = new CancellationTokenSource ();
var channel = Channel.CreateUnbounded<DiscoveryDevice>();

var discoverTask = onvifDiscovery.DiscoverAsync(channel.Writer, 1, cancellationToken);
await foreach (var device in channel.Reader.ReadAllAsync(cancellationToken))
{
    // New device discovered
}

Obsolete methods from version 1.X

When you update to version 2 you can see that previous available methods are marked as obsolete. Please use the new methods explained above as they have better support for asynchronous programming.

onvif-discovery's People

Contributors

jeremyvignelles avatar vicmaeg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

onvif-discovery's Issues

Duplicate and wrong Model, Manufacturer name

Hi,

If Manufacturer name contain space character as "Flir System", your lib only detect "Flir".
ảnh

onvif://www.onvif.org/type/Network_Video_Transmitter onvif://www.onvif.org/type/ptz onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/video_analytics onvif://www.onvif.org/name/ONVIF_ICAMERA onvif://www.onvif.org/hardware/MSTAR_IPNC onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/location/China onvif://www.onvif.org/location/Shenzhen
onvif://www.onvif.org/type/Network_Video_Transmitter onvif://www.onvif.org/type/ptz onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/video_analytics onvif://www.onvif.org/name/ONVIF_ICAMERA onvif://www.onvif.org/hardware/MSTAR_IPNC onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/location/China onvif://www.onvif.org/location/Shenzhen
onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/hardware/CM-6204-11-I onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/Profile/G onvif://www.onvif.org/name/FLIR%20CM-6204-11-I%20K816600858 onvif://www.onvif.org/manufacturer/FLIR%20Systems onvif://www.onvif.org/manufacturer/DVTel dvtel://www.dvtel.com/quasar/gen2/quadhd flir://www.flir.com/security/quasar/gen2/quadhd onvif://www.onvif.org/location/country/America onvif://www.onvif.org/location/country/America onvif://www.onvif.org/acc/uuid/0b6b62ea-b49a-49dc-906a-001bd880cd6c onvif://www.onvif.org/acc/mac/00-1b-d8-80-cd-6c onvif://www.onvif.org/acc/firmware/version/fs20160805NSZ onvif://www.onvif.org/acc/mfr/FLIR%20Systems
onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/hardware/CM-6204-11-I onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/Profile/G onvif://www.onvif.org/name/FLIR%20CM-6204-11-I%20K816600858 onvif://www.onvif.org/manufacturer/FLIR%20Systems onvif://www.onvif.org/manufacturer/DVTel dvtel://www.dvtel.com/quasar/gen2/quadhd flir://www.flir.com/security/quasar/gen2/quadhd onvif://www.onvif.org/location/country/America onvif://www.onvif.org/location/country/America onvif://www.onvif.org/acc/uuid/0b6b62ea-b49a-49dc-906a-001bd880cd6c onvif://www.onvif.org/acc/mac/00-1b-d8-80-cd-6c onvif://www.onvif.org/acc/firmware/version/fs20160805NSZ onvif://www.onvif.org/acc/mfr/FLIR%20Systems
onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/Network_Video_Transmitter onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/hardware/GV-UNP2500 onvif://www.onvif.org/location/country/taiwan onvif://www.onvif.org/name/Geovision onvif://www.onvif.org/acc/firmware/version/v3.12%202017-06-
onvif://www.onvif.org/name/Panasonic onvif://www.onvif.org/hardware/WV-V1330LK onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/Network_Video_Transmitter onvif://www.onvif.org/extension/unique_identifier onvif://www.onvif.org/location/office
onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/Network_Video_Transmitter onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/hardware/GV-UNP2500 onvif://www.onvif.org/location/country/taiwan onvif://www.onvif.org/name/Geovision onvif://www.onvif.org/acc/firmware/version/v3.12%202017-06-
onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/type/video_analytics onvif://www.onvif.org/hardware/2.0-H3M-DO1 onvif://www.onvif.org/avigilon/mac/00-18-85-14-3e-0a onvif://www.onvif.org/avigilon/firmware/version/2.6.0.150(15529) onvif://www.onvif.org/avigilon/scopes/changeId/sessionId/12688_3147 onvif://www.onvif.org/name/acc/Xu%e1%ba%a5t%20c%e1%ba%a3nh%204 onvif://www.onvif.org/location/acc/Xuat%20canh%204
onvif://www.onvif.org/name/Panasonic onvif://www.onvif.org/hardware/WV-V1330LK onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/Network_Video_Transmitter onvif://www.onvif.org/extension/unique_identifier onvif://www.onvif.org/location/office
onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/hardware/TC-C32TS%20SPEC%3AI8%2FA%2FE%2FY%2FM%2FH%2F2.7-13.5mm onvif://www.onvif.org/mfr/ipcamera onvif://www.onvif.org/location/country/china onvif://www.onvif.org/location/city/tianjin onvif://www.onvif.org/mac onvif://www.onvif.org/firmware/APP_V3.3.0.20200606 onvif://www.onvif.org/name/TC-C32TS%20SPEC%3AI8%2FA%2FE%2FY%2FM%2FH%2F2.7-13.5mm onvif://www.onvif.org/type/ipcamera onvif://www.onvif.org/Profile/G
onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/type/video_analytics onvif://www.onvif.org/hardware/2.0-H3M-DO1 onvif://www.onvif.org/avigilon/mac/00-18-85-14-3e-0a onvif://www.onvif.org/avigilon/firmware/version/2.6.0.150(15529) onvif://www.onvif.org/avigilon/scopes/changeId/sessionId/12688_3147 onvif://www.onvif.org/name/acc/Xu%e1%ba%a5t%20c%e1%ba%a3nh%204 onvif://www.onvif.org/location/acc/Xuat%20canh%204
onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/hardware/FI710-L onvif://www.onvif.org/location/country/China onvif://www.onvif.org/name/STD
onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/hardware/TC-C32TS%20SPEC%3AI8%2FA%2FE%2FY%2FM%2FH%2F2.7-13.5mm onvif://www.onvif.org/mfr/ipcamera onvif://www.onvif.org/location/country/china onvif://www.onvif.org/location/city/tianjin onvif://www.onvif.org/mac onvif://www.onvif.org/firmware/APP_V3.3.0.20200606 onvif://www.onvif.org/name/TC-C32TS%20SPEC%3AI8%2FA%2FE%2FY%2FM%2FH%2F2.7-13.5mm onvif://www.onvif.org/type/ipcamera onvif://www.onvif.org/Profile/G
onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/Profile/G onvif://www.onvif.org/type/basic onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/name/ArielFHDIPCamera onvif://www.onvif.org/hardware/CM-3102-11-I dvtel://www.dvtel.com/ariel/gen2 dvtel://www.dvtel.com/ariel/gen2/minidome onvif://www.onvif.org/location/ onvif://www.onvif.org/acc/uuid/98190dc2-0890-4ef8-ac9a-001bd8601f8d onvif://www.onvif.org/acc/mac/00-1b-d8-60-1f-8d onvif://www.onvif.org/acc/firmware/version/01.05.32.5 onvif://www.onvif.org/acc/mfr/FLIR%20Systems
onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/hardware/FI710-L onvif://www.onvif.org/location/country/China onvif://www.onvif.org/name/STD
onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/Profile/G onvif://www.onvif.org/type/basic onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/name/ArielFHDIPCamera onvif://www.onvif.org/hardware/CM-3102-11-I dvtel://www.dvtel.com/ariel/gen2 dvtel://www.dvtel.com/ariel/gen2/minidome onvif://www.onvif.org/location/ onvif://www.onvif.org/acc/uuid/98190dc2-0890-4ef8-ac9a-001bd8601f8d onvif://www.onvif.org/acc/mac/00-1b-d8-60-1f-8d onvif://www.onvif.org/acc/firmware/version/01.05.32.5 onvif://www.onvif.org/acc/mfr/FLIR%20Systems

Update 5.02 Core

Hello can you please update and also share a sample to connect over LTE/GSM or GPRS

Quick Start Guide?

Hello! I came across your package while trying to find tools to find my doorbell camera's rtsp streaming address.

I don't use Windows and am not well-versed in DotNet or C#. It would be helpful for me (and others like me) if an executable was included with this package or, failing that, a completely worked-out example of how to discover onvif devices on your network and write their properties to the console or file. The README is of some help, but it is incomplete. Your first example references local variables discovery and cancellationToken that are not declared anywhere.

UdpClientFactory filters to ethernet devices only

Hi,

I was wondering if there is a reason UdpClientFactory IsValidAdaptor filters to ethernet devices only?
This might limit usefulness on Xamarin platforms, not sure what NetworkInterfaceType is used on mobile devices.

It would be useful to us if discovery could probe wireless interfaces as well, thinking as an optional filter? (ie. ethernet only by default, but can configure with a list of NetworkInterfaceTypes to filter to)

Happy to create a P/R along these lines, does it sound like a reasonable feature to add?

Not Discovering the Device often

This solution is not discovering the device and throws OperationCanceledException often. @vmartos Please let me know if you face this issue before or if you know the solution?

Below is the block of code which is throwing exception instead of giving result.

public static async Task WithCancellation (this Task task, CancellationToken cancellationToken)
{
var tcs = new TaskCompletionSource ();
using (cancellationToken.Register (s => ((TaskCompletionSource)s).TrySetResult (true), tcs)) {
if (task != await Task.WhenAny (task, tcs.Task)) {
throw new OperationCanceledException (cancellationToken);
}
}
return await task;
}

crash when discovery

Some onvif system make crash the fonction DiscoveryDevice.
Because they send a null header. Like hikvision decoder.

To correct this i have add this in :

private DiscoveryDevice ProcessResponse(UdpReceiveResult response, Guid messageId)
       {
           if (response.Buffer != null)
           {
               string strResponse = Encoding.UTF8.GetString(response.Buffer);
               XmlProbeReponse xmlResponse = DeserializeResponse(strResponse);
               if (*_***xmlResponse.Header != null**_** && IsFromProbeMessage(messageId, xmlResponse)
                   && xmlResponse.Body.ProbeMatches.Any()
                   && !string.IsNullOrEmpty(xmlResponse.Body.ProbeMatches[0].Scopes))
               {
                   return DeviceFactory.CreateDevice(xmlResponse.Body.ProbeMatches[0], response.RemoteEndPoint);
               }
           }
           return null;
       }

crash during discovery

Hey @vmartos thanks for your library! I'm getting an exception on using Discover

try
            {
                var onvifDiscovery = new OnvifDiscovery.Discovery();
                var devices = (await onvifDiscovery.Discover(5)).ToList();
                lock (_lock)
                {
                    _discoveredDevices = devices;
                }
            }
            catch(Exception ex)
            {
                Logger.LogException(ex, "ONVIF Discovery");
            }           
  • it's always throwing an exception after the timeout finishes with "An existing connection was forcibly closed by the remote host".

_discoveredDevices is never populated. This is a net standard 2.0 project.

Stack trace:

" at System.Net.Sockets.Socket.DoBeginReceiveFrom(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint endPointSnapshot, SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
at System.Net.Sockets.Socket.BeginReceiveFrom(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint& remoteEP, AsyncCallback callback, Object state)
at System.Net.Sockets.UdpClient.BeginReceive(AsyncCallback requestCallback, Object state)
at System.Threading.Tasks.TaskFactory1.FromAsyncImpl(Func3 beginMethod, Func2 endFunction, Action1 endAction, Object state, TaskCreationOptions creationOptions)
at System.Net.Sockets.UdpClient.ReceiveAsync()
at OnvifDiscovery.Client.OnvifUdpClient.d__3.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at OnvifDiscovery.Common.ExtensionMethods.d__01.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at OnvifDiscovery.Common.ExtensionMethods.<WithCancellation>d__01.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at OnvifDiscovery.Discovery.d__4.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at OnvifDiscovery.Discovery.d__3.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at CoreLogic.Onvif.Discovery.d__6.MoveNext() in D:\Projects\agent-service\CoreLogic2\Onvif\Discovery.cs:line 51"

Return devices as they reply

Hi,
We're considering using your library in our project.

We have a UI where we want to show the discovered devices, and users would expect devices to appear quite immediately, while the scan can last 30seconds.

Unfortunately, this is not possible with the current API because of this line:

https://github.com/vmartos/onvif-discovery/blob/c231b1df95039761d3f6ea09ff8ef3fe32864412/OnvifDiscovery/Discovery.cs#L50

A new API entry point could be created with this signature:

public async Task Discover(Action<DiscoveryDevice> onDeviceDiscovered, int timeout, CancellationToken cancellationToken = default)

Thanks to the onDeviceDiscovered callback, items could be made available as they reply.
To avoid code duplication, the current entry point could be a wrapper around this new method, like so:

public async Task<IEnumerable<DiscoveryDevice>> Discover (int timeout, CancellationToken cancellationToken = default)
{
	var devices = new List<DiscoveryDevice> ();
	await this.Discover(devices.Add, timeout, cancellationToken);
	return devices;
}

What do you think?
We can make the PR if you want.

Detect ONVIF MessageVersion

Hello thanks for the code!
Any way to add in the message version into the discovery results, like
Soap12WSAddressing10, Soap11WSAddressingAugust2004, Soap12WSAddressing10, Soap12WSAddressingAugust2004 or Soap11?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.