Discover all devices on LAN

Multi tool use
Multi tool use





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















In my Xamarin Forms application, I am trying to discover all devices on the local network that I am connected to. My approach is to first get the device IP address, and use to first 3 numbers to know what the gateway is (first number is always 192). And then, ping every address on that gateway. Here is my code:



public partial class MainPage : ContentPage
{
private List<Device> discoveredDevices = new List<Device>();

public MainPage()
{
InitializeComponent();

Ping_all();
}

private string GetCurrentIp()
{
IPAddress addresses = Dns.GetHostAddresses(Dns.GetHostName());
string ipAddress = string.Empty;
if (addresses != null && addresses[0] != null)
{
ipAddress = addresses[0].ToString();
}
else
{
ipAddress = null;
}

return ipAddress;
}

public void Ping_all()
{
string ip = GetCurrentIp();

if (ip != null)
{
//Extracting and pinging all other ip's.
string array = ip.Split('.');
string gateway = array[0] + "." + array[1] + "." + array[2];

for (int i = 2; i <= 255; i++)
{
string ping_var = $"{gateway}.{i}";

//time in milliseconds
Ping(ping_var, 4, 4000);
}
}
}

public void Ping(string host, int attempts, int timeout)
{
for (int i = 0; i < attempts; i++)
{
new Thread(delegate ()
{
try
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);
// PingCompleted never gets called
}
catch(Exception e)
{
// Do nothing and let it try again until the attempts are exausted.
// Exceptions are thrown for normal ping failurs like address lookup
// failed. For this reason we are supressing errors.
}
}).Start();
}
}

private void PingCompleted(object sender, PingCompletedEventArgs e)
{
string ip = (string)e.UserState;
if (e.Reply != null && e.Reply.Status == IPStatus.Success)
{
string hostname = GetHostName(ip);
string macaddres = GetMacAddress(ip);

var device = new Device()
{
Hostname = hostname,
IpAddress = ip,
MacAddress = macaddres
};

discoveredDevices.Add(device);
}
}

public string GetHostName(string ipAddress)
{
try
{
IPHostEntry entry = Dns.GetHostEntry(ipAddress);
if (entry != null)
{
return entry.HostName;
}
}
catch (SocketException)
{

}

return null;
}

public string GetMacAddress(string ipAddress)
{
string macAddress = string.Empty;
System.Diagnostics.Process Process = new System.Diagnostics.Process();
Process.StartInfo.FileName = "arp";
Process.StartInfo.Arguments = "-a " + ipAddress;
Process.StartInfo.UseShellExecute = false;
Process.StartInfo.RedirectStandardOutput = true;
Process.StartInfo.CreateNoWindow = true;
Process.Start();
string strOutput = Process.StandardOutput.ReadToEnd();
string substrings = strOutput.Split('-');
if (substrings.Length >= 8)
{
macAddress = substrings[3].Substring(Math.Max(0, substrings[3].Length - 2))
+ "-" + substrings[4] + "-" + substrings[5] + "-" + substrings[6]
+ "-" + substrings[7] + "-"
+ substrings[8].Substring(0, 2);
return macAddress;
}
else
{
return "OWN Machine";
}
}
}


I get to the part where I try to ping:



System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);


But PingCompleted never gets called. No exception is thrown either. Any idea why? I'm running this on a physical Android device.



EDIT



PingCompleted started getting called for me now, not sure why it wasn't working before. But it now crashes in my GetMacAddress function on the line Process.Start(); because it can not find the resource.










share|improve this question




















  • 4





    not every device responds to a ping request

    – Jason
    Jan 3 at 22:14






  • 1





    Neither here nor there, but the gateway is not always at x.x.x.1. I've often seen it at x.x.x.255.

    – Kirk Woll
    Jan 3 at 22:15











  • I tried using the Fing app from the Google Play Store and it finds 14 different devices. So it must be something I'm doing wrong.

    – Darius
    Jan 3 at 22:16






  • 1





    It depends on subnet mask if it is ip/24 yes same but otherwise it is not

    – Derviş Kayımbaşıoğlu
    Jan 3 at 22:27






  • 2





    Note that arp (in this context) is a Windows command/program and is unlikely to work on a non-Windows device. On a phone/mobile device there isn't much use for Process.Start() other than to open a local file or URLs/URIs.

    – Visual Vincent
    Jan 3 at 23:19




















1















In my Xamarin Forms application, I am trying to discover all devices on the local network that I am connected to. My approach is to first get the device IP address, and use to first 3 numbers to know what the gateway is (first number is always 192). And then, ping every address on that gateway. Here is my code:



public partial class MainPage : ContentPage
{
private List<Device> discoveredDevices = new List<Device>();

public MainPage()
{
InitializeComponent();

Ping_all();
}

private string GetCurrentIp()
{
IPAddress addresses = Dns.GetHostAddresses(Dns.GetHostName());
string ipAddress = string.Empty;
if (addresses != null && addresses[0] != null)
{
ipAddress = addresses[0].ToString();
}
else
{
ipAddress = null;
}

return ipAddress;
}

public void Ping_all()
{
string ip = GetCurrentIp();

if (ip != null)
{
//Extracting and pinging all other ip's.
string array = ip.Split('.');
string gateway = array[0] + "." + array[1] + "." + array[2];

for (int i = 2; i <= 255; i++)
{
string ping_var = $"{gateway}.{i}";

//time in milliseconds
Ping(ping_var, 4, 4000);
}
}
}

public void Ping(string host, int attempts, int timeout)
{
for (int i = 0; i < attempts; i++)
{
new Thread(delegate ()
{
try
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);
// PingCompleted never gets called
}
catch(Exception e)
{
// Do nothing and let it try again until the attempts are exausted.
// Exceptions are thrown for normal ping failurs like address lookup
// failed. For this reason we are supressing errors.
}
}).Start();
}
}

private void PingCompleted(object sender, PingCompletedEventArgs e)
{
string ip = (string)e.UserState;
if (e.Reply != null && e.Reply.Status == IPStatus.Success)
{
string hostname = GetHostName(ip);
string macaddres = GetMacAddress(ip);

var device = new Device()
{
Hostname = hostname,
IpAddress = ip,
MacAddress = macaddres
};

discoveredDevices.Add(device);
}
}

public string GetHostName(string ipAddress)
{
try
{
IPHostEntry entry = Dns.GetHostEntry(ipAddress);
if (entry != null)
{
return entry.HostName;
}
}
catch (SocketException)
{

}

return null;
}

public string GetMacAddress(string ipAddress)
{
string macAddress = string.Empty;
System.Diagnostics.Process Process = new System.Diagnostics.Process();
Process.StartInfo.FileName = "arp";
Process.StartInfo.Arguments = "-a " + ipAddress;
Process.StartInfo.UseShellExecute = false;
Process.StartInfo.RedirectStandardOutput = true;
Process.StartInfo.CreateNoWindow = true;
Process.Start();
string strOutput = Process.StandardOutput.ReadToEnd();
string substrings = strOutput.Split('-');
if (substrings.Length >= 8)
{
macAddress = substrings[3].Substring(Math.Max(0, substrings[3].Length - 2))
+ "-" + substrings[4] + "-" + substrings[5] + "-" + substrings[6]
+ "-" + substrings[7] + "-"
+ substrings[8].Substring(0, 2);
return macAddress;
}
else
{
return "OWN Machine";
}
}
}


I get to the part where I try to ping:



System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);


But PingCompleted never gets called. No exception is thrown either. Any idea why? I'm running this on a physical Android device.



EDIT



PingCompleted started getting called for me now, not sure why it wasn't working before. But it now crashes in my GetMacAddress function on the line Process.Start(); because it can not find the resource.










share|improve this question




















  • 4





    not every device responds to a ping request

    – Jason
    Jan 3 at 22:14






  • 1





    Neither here nor there, but the gateway is not always at x.x.x.1. I've often seen it at x.x.x.255.

    – Kirk Woll
    Jan 3 at 22:15











  • I tried using the Fing app from the Google Play Store and it finds 14 different devices. So it must be something I'm doing wrong.

    – Darius
    Jan 3 at 22:16






  • 1





    It depends on subnet mask if it is ip/24 yes same but otherwise it is not

    – Derviş Kayımbaşıoğlu
    Jan 3 at 22:27






  • 2





    Note that arp (in this context) is a Windows command/program and is unlikely to work on a non-Windows device. On a phone/mobile device there isn't much use for Process.Start() other than to open a local file or URLs/URIs.

    – Visual Vincent
    Jan 3 at 23:19
















1












1








1


1






In my Xamarin Forms application, I am trying to discover all devices on the local network that I am connected to. My approach is to first get the device IP address, and use to first 3 numbers to know what the gateway is (first number is always 192). And then, ping every address on that gateway. Here is my code:



public partial class MainPage : ContentPage
{
private List<Device> discoveredDevices = new List<Device>();

public MainPage()
{
InitializeComponent();

Ping_all();
}

private string GetCurrentIp()
{
IPAddress addresses = Dns.GetHostAddresses(Dns.GetHostName());
string ipAddress = string.Empty;
if (addresses != null && addresses[0] != null)
{
ipAddress = addresses[0].ToString();
}
else
{
ipAddress = null;
}

return ipAddress;
}

public void Ping_all()
{
string ip = GetCurrentIp();

if (ip != null)
{
//Extracting and pinging all other ip's.
string array = ip.Split('.');
string gateway = array[0] + "." + array[1] + "." + array[2];

for (int i = 2; i <= 255; i++)
{
string ping_var = $"{gateway}.{i}";

//time in milliseconds
Ping(ping_var, 4, 4000);
}
}
}

public void Ping(string host, int attempts, int timeout)
{
for (int i = 0; i < attempts; i++)
{
new Thread(delegate ()
{
try
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);
// PingCompleted never gets called
}
catch(Exception e)
{
// Do nothing and let it try again until the attempts are exausted.
// Exceptions are thrown for normal ping failurs like address lookup
// failed. For this reason we are supressing errors.
}
}).Start();
}
}

private void PingCompleted(object sender, PingCompletedEventArgs e)
{
string ip = (string)e.UserState;
if (e.Reply != null && e.Reply.Status == IPStatus.Success)
{
string hostname = GetHostName(ip);
string macaddres = GetMacAddress(ip);

var device = new Device()
{
Hostname = hostname,
IpAddress = ip,
MacAddress = macaddres
};

discoveredDevices.Add(device);
}
}

public string GetHostName(string ipAddress)
{
try
{
IPHostEntry entry = Dns.GetHostEntry(ipAddress);
if (entry != null)
{
return entry.HostName;
}
}
catch (SocketException)
{

}

return null;
}

public string GetMacAddress(string ipAddress)
{
string macAddress = string.Empty;
System.Diagnostics.Process Process = new System.Diagnostics.Process();
Process.StartInfo.FileName = "arp";
Process.StartInfo.Arguments = "-a " + ipAddress;
Process.StartInfo.UseShellExecute = false;
Process.StartInfo.RedirectStandardOutput = true;
Process.StartInfo.CreateNoWindow = true;
Process.Start();
string strOutput = Process.StandardOutput.ReadToEnd();
string substrings = strOutput.Split('-');
if (substrings.Length >= 8)
{
macAddress = substrings[3].Substring(Math.Max(0, substrings[3].Length - 2))
+ "-" + substrings[4] + "-" + substrings[5] + "-" + substrings[6]
+ "-" + substrings[7] + "-"
+ substrings[8].Substring(0, 2);
return macAddress;
}
else
{
return "OWN Machine";
}
}
}


I get to the part where I try to ping:



System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);


But PingCompleted never gets called. No exception is thrown either. Any idea why? I'm running this on a physical Android device.



EDIT



PingCompleted started getting called for me now, not sure why it wasn't working before. But it now crashes in my GetMacAddress function on the line Process.Start(); because it can not find the resource.










share|improve this question
















In my Xamarin Forms application, I am trying to discover all devices on the local network that I am connected to. My approach is to first get the device IP address, and use to first 3 numbers to know what the gateway is (first number is always 192). And then, ping every address on that gateway. Here is my code:



public partial class MainPage : ContentPage
{
private List<Device> discoveredDevices = new List<Device>();

public MainPage()
{
InitializeComponent();

Ping_all();
}

private string GetCurrentIp()
{
IPAddress addresses = Dns.GetHostAddresses(Dns.GetHostName());
string ipAddress = string.Empty;
if (addresses != null && addresses[0] != null)
{
ipAddress = addresses[0].ToString();
}
else
{
ipAddress = null;
}

return ipAddress;
}

public void Ping_all()
{
string ip = GetCurrentIp();

if (ip != null)
{
//Extracting and pinging all other ip's.
string array = ip.Split('.');
string gateway = array[0] + "." + array[1] + "." + array[2];

for (int i = 2; i <= 255; i++)
{
string ping_var = $"{gateway}.{i}";

//time in milliseconds
Ping(ping_var, 4, 4000);
}
}
}

public void Ping(string host, int attempts, int timeout)
{
for (int i = 0; i < attempts; i++)
{
new Thread(delegate ()
{
try
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);
// PingCompleted never gets called
}
catch(Exception e)
{
// Do nothing and let it try again until the attempts are exausted.
// Exceptions are thrown for normal ping failurs like address lookup
// failed. For this reason we are supressing errors.
}
}).Start();
}
}

private void PingCompleted(object sender, PingCompletedEventArgs e)
{
string ip = (string)e.UserState;
if (e.Reply != null && e.Reply.Status == IPStatus.Success)
{
string hostname = GetHostName(ip);
string macaddres = GetMacAddress(ip);

var device = new Device()
{
Hostname = hostname,
IpAddress = ip,
MacAddress = macaddres
};

discoveredDevices.Add(device);
}
}

public string GetHostName(string ipAddress)
{
try
{
IPHostEntry entry = Dns.GetHostEntry(ipAddress);
if (entry != null)
{
return entry.HostName;
}
}
catch (SocketException)
{

}

return null;
}

public string GetMacAddress(string ipAddress)
{
string macAddress = string.Empty;
System.Diagnostics.Process Process = new System.Diagnostics.Process();
Process.StartInfo.FileName = "arp";
Process.StartInfo.Arguments = "-a " + ipAddress;
Process.StartInfo.UseShellExecute = false;
Process.StartInfo.RedirectStandardOutput = true;
Process.StartInfo.CreateNoWindow = true;
Process.Start();
string strOutput = Process.StandardOutput.ReadToEnd();
string substrings = strOutput.Split('-');
if (substrings.Length >= 8)
{
macAddress = substrings[3].Substring(Math.Max(0, substrings[3].Length - 2))
+ "-" + substrings[4] + "-" + substrings[5] + "-" + substrings[6]
+ "-" + substrings[7] + "-"
+ substrings[8].Substring(0, 2);
return macAddress;
}
else
{
return "OWN Machine";
}
}
}


I get to the part where I try to ping:



System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
ping.PingCompleted += new PingCompletedEventHandler(PingCompleted);
ping.SendAsync(host, timeout, host);


But PingCompleted never gets called. No exception is thrown either. Any idea why? I'm running this on a physical Android device.



EDIT



PingCompleted started getting called for me now, not sure why it wasn't working before. But it now crashes in my GetMacAddress function on the line Process.Start(); because it can not find the resource.







c# xamarin.forms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 22:24







Darius

















asked Jan 3 at 22:12









DariusDarius

58011644




58011644








  • 4





    not every device responds to a ping request

    – Jason
    Jan 3 at 22:14






  • 1





    Neither here nor there, but the gateway is not always at x.x.x.1. I've often seen it at x.x.x.255.

    – Kirk Woll
    Jan 3 at 22:15











  • I tried using the Fing app from the Google Play Store and it finds 14 different devices. So it must be something I'm doing wrong.

    – Darius
    Jan 3 at 22:16






  • 1





    It depends on subnet mask if it is ip/24 yes same but otherwise it is not

    – Derviş Kayımbaşıoğlu
    Jan 3 at 22:27






  • 2





    Note that arp (in this context) is a Windows command/program and is unlikely to work on a non-Windows device. On a phone/mobile device there isn't much use for Process.Start() other than to open a local file or URLs/URIs.

    – Visual Vincent
    Jan 3 at 23:19
















  • 4





    not every device responds to a ping request

    – Jason
    Jan 3 at 22:14






  • 1





    Neither here nor there, but the gateway is not always at x.x.x.1. I've often seen it at x.x.x.255.

    – Kirk Woll
    Jan 3 at 22:15











  • I tried using the Fing app from the Google Play Store and it finds 14 different devices. So it must be something I'm doing wrong.

    – Darius
    Jan 3 at 22:16






  • 1





    It depends on subnet mask if it is ip/24 yes same but otherwise it is not

    – Derviş Kayımbaşıoğlu
    Jan 3 at 22:27






  • 2





    Note that arp (in this context) is a Windows command/program and is unlikely to work on a non-Windows device. On a phone/mobile device there isn't much use for Process.Start() other than to open a local file or URLs/URIs.

    – Visual Vincent
    Jan 3 at 23:19










4




4





not every device responds to a ping request

– Jason
Jan 3 at 22:14





not every device responds to a ping request

– Jason
Jan 3 at 22:14




1




1





Neither here nor there, but the gateway is not always at x.x.x.1. I've often seen it at x.x.x.255.

– Kirk Woll
Jan 3 at 22:15





Neither here nor there, but the gateway is not always at x.x.x.1. I've often seen it at x.x.x.255.

– Kirk Woll
Jan 3 at 22:15













I tried using the Fing app from the Google Play Store and it finds 14 different devices. So it must be something I'm doing wrong.

– Darius
Jan 3 at 22:16





I tried using the Fing app from the Google Play Store and it finds 14 different devices. So it must be something I'm doing wrong.

– Darius
Jan 3 at 22:16




1




1





It depends on subnet mask if it is ip/24 yes same but otherwise it is not

– Derviş Kayımbaşıoğlu
Jan 3 at 22:27





It depends on subnet mask if it is ip/24 yes same but otherwise it is not

– Derviş Kayımbaşıoğlu
Jan 3 at 22:27




2




2





Note that arp (in this context) is a Windows command/program and is unlikely to work on a non-Windows device. On a phone/mobile device there isn't much use for Process.Start() other than to open a local file or URLs/URIs.

– Visual Vincent
Jan 3 at 23:19







Note that arp (in this context) is a Windows command/program and is unlikely to work on a non-Windows device. On a phone/mobile device there isn't much use for Process.Start() other than to open a local file or URLs/URIs.

– Visual Vincent
Jan 3 at 23:19














1 Answer
1






active

oldest

votes


















0














I ended up using this really robust and easy to use library:



https://github.com/Yortw/RSSDP



It doesn't actually find all devices on the network, instead it uses SSDP (Simple Search Discovery Protocol) to quickly find all devices that are broadcasting a service with this protocol on the network. I filtered it to only scan devices running my app, which is what I actually needed. It takes only a second to discover my devices, which is much faster than pinging 255 addresses.



In the documentation you will see:



var deviceDefinition = new SsdpRootDevice()
{
CacheLifetime = TimeSpan.FromMinutes(30), //How long SSDP clients can cache this info.
Location = new Uri("http://mydevice/descriptiondocument.xml"), // Must point to the URL that serves your devices UPnP description document.
DeviceTypeNamespace = "my-namespace",
DeviceType = "MyCustomDevice",
FriendlyName = "Custom Device 1",
Manufacturer = "Me",
ModelName = "MyCustomDevice",
Uuid = GetPersistentUuid() // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
};


For the Location I set it as my device's IP. So that another device that discovers it can have the IP too. I don't think it's meant to be used this way, but it worked for me and I don't see why not.



I tested it on 2 physical Android devices.






share|improve this answer
























  • Darius, I am too new to Xamarin and SSDP, and need some help , I too need a device discovery APP, and would need a sample code on how to get done. I hove been looking every where until I humped into your post. please help me out.

    – Shrimant Patel
    Mar 29 at 23:39











  • Your requirements may differ from mine. I need to discover devices that are running my app, not all the devices. If that's what you need, install the plugin as a nuget package. Follow the sample code in the documentation to see how to publish a device, as well as discover other devices. Then do as I suggested in my post and set the Location as your IP address. I no longer have the sample code that I wrote as I moved on to a different project.

    – Darius
    Mar 31 at 18:04












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030495%2fdiscover-all-devices-on-lan%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I ended up using this really robust and easy to use library:



https://github.com/Yortw/RSSDP



It doesn't actually find all devices on the network, instead it uses SSDP (Simple Search Discovery Protocol) to quickly find all devices that are broadcasting a service with this protocol on the network. I filtered it to only scan devices running my app, which is what I actually needed. It takes only a second to discover my devices, which is much faster than pinging 255 addresses.



In the documentation you will see:



var deviceDefinition = new SsdpRootDevice()
{
CacheLifetime = TimeSpan.FromMinutes(30), //How long SSDP clients can cache this info.
Location = new Uri("http://mydevice/descriptiondocument.xml"), // Must point to the URL that serves your devices UPnP description document.
DeviceTypeNamespace = "my-namespace",
DeviceType = "MyCustomDevice",
FriendlyName = "Custom Device 1",
Manufacturer = "Me",
ModelName = "MyCustomDevice",
Uuid = GetPersistentUuid() // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
};


For the Location I set it as my device's IP. So that another device that discovers it can have the IP too. I don't think it's meant to be used this way, but it worked for me and I don't see why not.



I tested it on 2 physical Android devices.






share|improve this answer
























  • Darius, I am too new to Xamarin and SSDP, and need some help , I too need a device discovery APP, and would need a sample code on how to get done. I hove been looking every where until I humped into your post. please help me out.

    – Shrimant Patel
    Mar 29 at 23:39











  • Your requirements may differ from mine. I need to discover devices that are running my app, not all the devices. If that's what you need, install the plugin as a nuget package. Follow the sample code in the documentation to see how to publish a device, as well as discover other devices. Then do as I suggested in my post and set the Location as your IP address. I no longer have the sample code that I wrote as I moved on to a different project.

    – Darius
    Mar 31 at 18:04
















0














I ended up using this really robust and easy to use library:



https://github.com/Yortw/RSSDP



It doesn't actually find all devices on the network, instead it uses SSDP (Simple Search Discovery Protocol) to quickly find all devices that are broadcasting a service with this protocol on the network. I filtered it to only scan devices running my app, which is what I actually needed. It takes only a second to discover my devices, which is much faster than pinging 255 addresses.



In the documentation you will see:



var deviceDefinition = new SsdpRootDevice()
{
CacheLifetime = TimeSpan.FromMinutes(30), //How long SSDP clients can cache this info.
Location = new Uri("http://mydevice/descriptiondocument.xml"), // Must point to the URL that serves your devices UPnP description document.
DeviceTypeNamespace = "my-namespace",
DeviceType = "MyCustomDevice",
FriendlyName = "Custom Device 1",
Manufacturer = "Me",
ModelName = "MyCustomDevice",
Uuid = GetPersistentUuid() // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
};


For the Location I set it as my device's IP. So that another device that discovers it can have the IP too. I don't think it's meant to be used this way, but it worked for me and I don't see why not.



I tested it on 2 physical Android devices.






share|improve this answer
























  • Darius, I am too new to Xamarin and SSDP, and need some help , I too need a device discovery APP, and would need a sample code on how to get done. I hove been looking every where until I humped into your post. please help me out.

    – Shrimant Patel
    Mar 29 at 23:39











  • Your requirements may differ from mine. I need to discover devices that are running my app, not all the devices. If that's what you need, install the plugin as a nuget package. Follow the sample code in the documentation to see how to publish a device, as well as discover other devices. Then do as I suggested in my post and set the Location as your IP address. I no longer have the sample code that I wrote as I moved on to a different project.

    – Darius
    Mar 31 at 18:04














0












0








0







I ended up using this really robust and easy to use library:



https://github.com/Yortw/RSSDP



It doesn't actually find all devices on the network, instead it uses SSDP (Simple Search Discovery Protocol) to quickly find all devices that are broadcasting a service with this protocol on the network. I filtered it to only scan devices running my app, which is what I actually needed. It takes only a second to discover my devices, which is much faster than pinging 255 addresses.



In the documentation you will see:



var deviceDefinition = new SsdpRootDevice()
{
CacheLifetime = TimeSpan.FromMinutes(30), //How long SSDP clients can cache this info.
Location = new Uri("http://mydevice/descriptiondocument.xml"), // Must point to the URL that serves your devices UPnP description document.
DeviceTypeNamespace = "my-namespace",
DeviceType = "MyCustomDevice",
FriendlyName = "Custom Device 1",
Manufacturer = "Me",
ModelName = "MyCustomDevice",
Uuid = GetPersistentUuid() // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
};


For the Location I set it as my device's IP. So that another device that discovers it can have the IP too. I don't think it's meant to be used this way, but it worked for me and I don't see why not.



I tested it on 2 physical Android devices.






share|improve this answer













I ended up using this really robust and easy to use library:



https://github.com/Yortw/RSSDP



It doesn't actually find all devices on the network, instead it uses SSDP (Simple Search Discovery Protocol) to quickly find all devices that are broadcasting a service with this protocol on the network. I filtered it to only scan devices running my app, which is what I actually needed. It takes only a second to discover my devices, which is much faster than pinging 255 addresses.



In the documentation you will see:



var deviceDefinition = new SsdpRootDevice()
{
CacheLifetime = TimeSpan.FromMinutes(30), //How long SSDP clients can cache this info.
Location = new Uri("http://mydevice/descriptiondocument.xml"), // Must point to the URL that serves your devices UPnP description document.
DeviceTypeNamespace = "my-namespace",
DeviceType = "MyCustomDevice",
FriendlyName = "Custom Device 1",
Manufacturer = "Me",
ModelName = "MyCustomDevice",
Uuid = GetPersistentUuid() // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc.
};


For the Location I set it as my device's IP. So that another device that discovers it can have the IP too. I don't think it's meant to be used this way, but it worked for me and I don't see why not.



I tested it on 2 physical Android devices.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 7 at 17:14









DariusDarius

58011644




58011644













  • Darius, I am too new to Xamarin and SSDP, and need some help , I too need a device discovery APP, and would need a sample code on how to get done. I hove been looking every where until I humped into your post. please help me out.

    – Shrimant Patel
    Mar 29 at 23:39











  • Your requirements may differ from mine. I need to discover devices that are running my app, not all the devices. If that's what you need, install the plugin as a nuget package. Follow the sample code in the documentation to see how to publish a device, as well as discover other devices. Then do as I suggested in my post and set the Location as your IP address. I no longer have the sample code that I wrote as I moved on to a different project.

    – Darius
    Mar 31 at 18:04



















  • Darius, I am too new to Xamarin and SSDP, and need some help , I too need a device discovery APP, and would need a sample code on how to get done. I hove been looking every where until I humped into your post. please help me out.

    – Shrimant Patel
    Mar 29 at 23:39











  • Your requirements may differ from mine. I need to discover devices that are running my app, not all the devices. If that's what you need, install the plugin as a nuget package. Follow the sample code in the documentation to see how to publish a device, as well as discover other devices. Then do as I suggested in my post and set the Location as your IP address. I no longer have the sample code that I wrote as I moved on to a different project.

    – Darius
    Mar 31 at 18:04

















Darius, I am too new to Xamarin and SSDP, and need some help , I too need a device discovery APP, and would need a sample code on how to get done. I hove been looking every where until I humped into your post. please help me out.

– Shrimant Patel
Mar 29 at 23:39





Darius, I am too new to Xamarin and SSDP, and need some help , I too need a device discovery APP, and would need a sample code on how to get done. I hove been looking every where until I humped into your post. please help me out.

– Shrimant Patel
Mar 29 at 23:39













Your requirements may differ from mine. I need to discover devices that are running my app, not all the devices. If that's what you need, install the plugin as a nuget package. Follow the sample code in the documentation to see how to publish a device, as well as discover other devices. Then do as I suggested in my post and set the Location as your IP address. I no longer have the sample code that I wrote as I moved on to a different project.

– Darius
Mar 31 at 18:04





Your requirements may differ from mine. I need to discover devices that are running my app, not all the devices. If that's what you need, install the plugin as a nuget package. Follow the sample code in the documentation to see how to publish a device, as well as discover other devices. Then do as I suggested in my post and set the Location as your IP address. I no longer have the sample code that I wrote as I moved on to a different project.

– Darius
Mar 31 at 18:04




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030495%2fdiscover-all-devices-on-lan%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







SKq5MwB3F,OEpw811,3X6iL9i mfCEdU5Z9 Yc4e
hFUZ K 8Q aOTMw QHgkg5GML2cejoW

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas