Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Finding all Netduino Plus(s) on a network


  • Please log in to reply
18 replies to this topic

#1 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 25 January 2013 - 10:35 PM

Has anyone played around with Enumerating all Netduinos on a Network?  Say you have a bunch of them all set for DHCP and I'd like to find them all from a windows app.  I've played around with NetServerEnum function but I don't think I'm seeing everything on my network.



#2 Strut

Strut

    Member

  • Members
  • PipPip
  • 18 posts

Posted 25 January 2013 - 11:36 PM

I didn't see anything in the netmf networking stack to make this easy. I believe NetServerEnum is only going to work for full-fledged Windows OS, I think you could open a socket on an obscure port on each duino and then just sweep or broadcast the subnet looking for a (predefined?) response from your nodes.

 

I'm thinking of doing something similar, but I plan on handling everything on the netduinos. I plan to make a wireless/wired mesh of cooperative devices that are aware of each other and are capable of taking over the delegation of services and duties if one falls off the network for any reason.


  • Dan T and JerseyTechGuy like this

#3 HiredMind

HiredMind

    Member

  • Members
  • PipPip
  • 25 posts

Posted 26 January 2013 - 12:15 AM

You could use a UDP broadcast to do this.  You send out a UDP packet to a special address that indicates the entire subnet (e.g. 192.168.1.255), and your Netduinos would respond to it.  I don't remember what to set the netmask to, but there are bound to be tutorials galore out there, as the technique is older than I am  :lol:


  • JerseyTechGuy likes this

#4 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 26 January 2013 - 12:25 AM

Hi Dave,

 

I am only looking  up one address, but what I do is do a ping sweep on the DHCP range to populate the the arp cache and then parse out the IP address from the arp table, given the Netduino MAC address. Something along these lines and calling the function for each of your Netduinos,

 

Public Function NetdunioIPAddress(ByVal MacAddress As String) As String        'Do a ping sweep to refresh the arp cache and then do an arp all to associate        'the MAC address with the IP address        Dim ps As New System.Diagnostics.ProcessStartInfo("ping.exe")        Dim Arguments As String = " -n 2 -w 100 192.168.0."        ps.CreateNoWindow = True        ps.UseShellExecute = False        ps.RedirectStandardOutput = True        Using proc As New System.Diagnostics.Process()            'ping sweep            For i As Integer = 100 To 150                ps.Arguments = Arguments & i.ToString                proc.StartInfo = ps                proc.Start()            Next        End Using        Dim arpArray() As String = {}        Dim arp As New System.Diagnostics.ProcessStartInfo("arp.exe")        arp.Arguments = " -a"        arp.CreateNoWindow = True        arp.UseShellExecute = False        arp.RedirectStandardOutput = True        Using proc As New System.Diagnostics.Process()            proc.StartInfo = arp            proc.Start()            Dim sr As System.IO.StreamReader = proc.StandardOutput            While Not proc.HasExited            End While            Dim sResults As String = sr.ReadToEnd()            arpArray = sResults.Split({" "c}, StringSplitOptions.RemoveEmptyEntries)            Dim mac As Integer = Array.FindIndex(Of String)(arpArray, AddressOf IndexOfMAC)            temp = arpArray(mac - 1).Trim        End Using        Return temp    End Function        Public Function IndexOfMAC(ByVal str As String) As Boolean        Return If(str.Trim = Form1.NetduinoMAC, True, False)    End Function

Baxter


  • JerseyTechGuy likes this

#5 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 26 January 2013 - 12:57 AM

Great Feedback Everyone.  I was just looking at UDP Multicast and using an obscure port for this.  Will play around and see what I come up with.



#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 28 January 2013 - 04:56 PM

After a lot of thinking and mapping out our entire planned product registration process I think I figure out an easier way of doing this all.  While it might have been nice to simply scan and find all of the Pandora's Box(s) on the network I think I'm going with a simple approach of looking up the MAC id to get the IP and HOSTNAME.  Since the end user will need to register their Pandora's Box on our site anyway, I'll likely include the MAC address as part of a serial number for the unit (ie: STPBR15C864A00520D).  Within this code is the MAC address of 5C-86-4A-00-52-0D.

 

Our windows app will then require the use of your username / password to run the software which will call a web service to get all of your registered Pandora's Box(s) and store them on the PC.  So each time you run the windows app, it will already have the MAC IDs and can lookup the IPs and HOSTNAMEs of all the Pandora's Box(s) you have registered with your program.



#7 Outthereman

Outthereman

    New Member

  • Members
  • Pip
  • 5 posts

Posted 28 January 2013 - 06:47 PM

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]Hi[/color]
 

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]I have done a lot of work using the arp table and Mac addresses to discover devices on a network.[/color]

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]I found that unless the device has been accessed from that machine, the mac will not appear on that machine's arp list. So what i do is to run a IMCP ping to populate my arp table and then based on the first few digits get a list of devices (The first few digits is the registation for the vendor)[/color]

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;] [/color]

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]if (ip.MacAddress.StartsWith("5c-86-4a-") == true)[/color]

 

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]{  [/color]

....

}

 

 

 


 


  • JerseyTechGuy likes this

#8 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 29 January 2013 - 11:46 AM

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]Hi[/color]
 

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]I have done a lot of work using the arp table and Mac addresses to discover devices on a network.[/color]

 

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]I found that unless the device has been accessed from that machine, the mac will not appear on that machine's arp list. So what i do is to run a IMCP ping to populate my arp table and then based on the first few digits get a list of devices (The first few digits is the registation for the vendor)[/color]

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;] [/color]

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]if (ip.MacAddress.StartsWith("5c-86-4a-") == true)[/color]

 

[color=rgb(34,34,34);font-family:Arial, 'sans-serif';font-size:10.5pt;]{  [/color]

....

}

 

 

 


 

Thanks for the tip.  I'll try this on my laptop later which hasn't access the Netduino, then add IMCP to the code and try again.



#9 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 29 January 2013 - 03:51 PM

So the end result is the following and I think this will work well.

 

1) People register the Netduino Devices by MAC address in the windows app. When the windows app runs it will show a list of all Netduinos and whether they are found (basically can the MAC resolve to an IP and NetBios name).  If they are not resolved the user has a "refresh" button to hit.

 

2) If the refresh is hit it will do the following:

 

  a ) Flush the ARP list using "arp -d".

  b ) Scan and Asynchronously ping all IPs on the network.  This will repopulate the arp list.

  c ) Search the ARP list "arp -a" for all Netduinos. If found then resolve the IP and NetBios name from the MAC.

 

3) The user list of Netduino is updated with the new "online" status.

 

So far my thrown together code works pretty well.  Will work on making some useful classes.



#10 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 29 January 2013 - 05:07 PM

Won't step 2a trigger some firewalls that block port scanning (and be slow)? Why not have an 'announce' at startup or part of a reset button?



#11 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 29 January 2013 - 06:13 PM

Won't step 2a trigger some firewalls that block port scanning (and be slow)? Why not have an 'announce' at startup or part of a reset button?

 

So far it scans fairly fast.  It hasn't triggered Windows or McAfee firewall thus far.

 

Not sure what you are referring to by 'announce'.  Are you referring to having the Netduinos announce themselves when on the network?



#12 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 29 January 2013 - 07:15 PM

Yes. It looks like part of the setup requires the box to 'call home' to get registered anyway. Or better, I guess it would be easier if the device could broadcast to a specific port (that your local software app would listen for on that specific port). Is UDP broadcast supported by the N+? 



#13 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 29 January 2013 - 07:53 PM

Actually it's a blackbox setup.  The windows app will only know the MAC addresses of the Netduino's you own.  The user has no ability to change any network settings on the netduinos.  The netduinos are running DHCP and will get an IP on the network and expose a NetBios name.  So the boxes don't know the users computer and the computer doesn't know the netduinos except we have a list of MAC addresses.

 

These users will be mostly considered "non technical" so the process needs to be simple.



#14 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 29 January 2013 - 08:28 PM

Here is a general flow chart of my planned registration -> purchase -> registration process.  This may help clarify the "black box" process I'm trying to create for the end user.  Pandora's Box refers to in the flowchart is a Netduino Plus 2 based product and there is an accompanying windows app for analyzing and charting the stored data.

 

Posted Image



#15 HiredMind

HiredMind

    Member

  • Members
  • PipPip
  • 25 posts

Posted 30 January 2013 - 12:32 AM

On our network, doing a ping sweep would definitely get you extra scrutiny from the admins.

 

:ph34r: :ph34r: :ph34r:



#16 HiredMind

HiredMind

    Member

  • Members
  • PipPip
  • 25 posts

Posted 30 January 2013 - 07:33 AM

Hi Dave -

 

I got curious about NetMF networking capabilities so I adapted some code to do UDP broadcast ping/response from an old library I wrote.  A solution is attached. Very little error checking and such.

 

It sends out a single packet to call, and a single packet for each response.  I believe that the ARP list would also be repopulated during this process as well - and only for the Netduino IPs - but I haven't fired up Ethereal to test that hypothesis.

 

A ping sweep sends out a packet for each IP address on the subnet, and one for each response, even the negative ones. Note that responses can come from routers too ("host unreachable", "no route to host", etc).  So, worst-case, for a class B subnet, that's 131,070 packets, plus all the ARP overhead at the Ethernet level.

Attached Files

  • Attached File  Udp.zip   9.12KB   11 downloads

  • JerseyTechGuy likes this

#17 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 30 January 2013 - 08:58 AM

HiredMind, That's awesome, thanks for sharing! I'm looking for something similar to enumerate one or two N+ on the network. The reply to the broadcast could be the MAC and IP address and any other status info, so no digging around or populating the ARP cache. I'm pretty sure this is how a lot of network printer managers work that find all the vendors printers on your network to install/setup drivers, etc. I've only got one N+ right now that's in use but have another on the way and will test this out. Thanks again.



#18 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 30 January 2013 - 11:17 AM

Hi Dave -

 

I got curious about NetMF networking capabilities so I adapted some code to do UDP broadcast ping/response from an old library I wrote.  A solution is attached. Very little error checking and such.

 

It sends out a single packet to call, and a single packet for each response.  I believe that the ARP list would also be repopulated during this process as well - and only for the Netduino IPs - but I haven't fired up Ethereal to test that hypothesis.

 

A ping sweep sends out a packet for each IP address on the subnet, and one for each response, even the negative ones. Note that responses can come from routers too ("host unreachable", "no route to host", etc).  So, worst-case, for a class B subnet, that's 131,070 packets, plus all the ARP overhead at the Ethernet level.

 

Thanks for the contribution.  I'll give it a shot later today and see what it does.



#19 Tim Orr

Tim Orr

    New Member

  • Members
  • Pip
  • 1 posts

Posted 31 January 2013 - 12:50 AM

The only problem you might run into with the arp cache is when your network is divided into subnets. When you ping a device on a different subnet, the router will respond to the arp request with its MAC address.

 

So you'd have the MAC address of the router instead of the Netduino in your arp cache.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.