Device/ Computer Discovery in my Network

30 views
Skip to first unread message

Alagappan M

unread,
Jun 26, 2014, 3:12:19 AM6/26/14
to nod...@googlegroups.com
I was trying to write a sample program for my test project to find out all the devices(like android or IOS) or other computers connected to the network to which my computer is connected.
I am able to see all the connected devices when I login to the router administration console and I want the same list using my program.
I tried the sample code below  which I came across the post at https://gist.github.com/chrishulbert/895382 and found it interesting and tried to use it, But i was not able to get the list. Am I missing something in the below code or this is a wrong sample I am referring to?. Any help would be greatly appreciated in this regard.

The Code
// Listen for responses
function listen(port) {
var server = dgram.createSocket("udp4");
server.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port);
});
server.bind(port); 

// setTimeout(function(){
// console.log("Finished waiting");
// server.close();
// },10000);
}
 
function search() {
var message = new Buffer(
"M-SEARCH * HTTP/1.1\r\n" +
"HOST:239.255.255.250:1900\r\n" +
"MAN:\"ssdp:discover\"\r\n" +
"ST:ssdp:all\r\n" + 
"MX:3\r\n" + 
"\r\n"
);
 
var client = dgram.createSocket("udp4");
client.bind(0,"",function() {
console.log(client.address().port);
listen(client.address().port);
client.send(message, 0, message.length, 1900, "239.255.255.250",function() {
// client.close();
});
}); // So that we get a port so we can listen before sending
}
search();
Reply all
Reply to author
Forward
0 new messages