Forums > MaxMSP

Sniffing IP addresses

Oct 26 2010 | 3:51 pm

I’m building various patches using networked computers and need to find a way to grab the IP addresses and host names of all the machines connected to the network.

The network is a private wireless LAN running from a cheap router, and will have a maximum of 12 machines connected to it. It doesn’t function as an internet gateway at the moment and there aren’t any plans to do this.

Ideally I need to find a way to populate a uMenu object with a list of the IP address assigned to each computer along with the name of the computer. My patches need to be able to send data to specified computers on the network (which have different roles), and it would be nice to be able to switch between them easily. At the moment I’m having to hardcode IP address onto both network interfaces and into the patches. It would be much nicer to have IP address allocation handled by the DHCP server and just grab the data from there (set-up time would be substantially reduced).

I’m aware that this can be done using standalone network sniffing software, but I’m not sure how this data could be easily transferred to Max and I’d definitely rather not have to install sniffing software on everyone’s machine prior to using the patch.

I’m no network expert so there may be some obvious solution staring me in the face – any pointers gratefully received!

Many thanks,


Oct 26 2010 | 3:57 pm

hi tim,

you can use the udpsend object to broadcast a message like "hello i am, who are you?" at loadbang and have IPs from other computers.

you have to implement your own logic but this is the basics.

have a look at [mxj net.local] to get the local ip address…


Oct 26 2010 | 3:57 pm

a DCHP router should be able to know already about devices when in automatic lease mode, no?
you could limit your 10 computers setup to a range between .0 and .10 so that you have to
scan only these 10 IPs.

i dont know about your setup .. but you might also want to / you might be able to make computers
tell the host their adresses by asksing them for it via a multicast IP.

Oct 26 2010 | 5:44 pm

Multicasting is a good way to query the computers. You could for instance use a metro to multicast the IP address of the server and then get all the other computers to respond to that. YOu can multicast using the maxj network objects very easily.

I was involved in a project using 50 networked computers over wireless and that was the approach I took. It worked well.

In my case I used the wireless MAC address to identify unique computers, specifically because IP addresses over wireless are not guaranteed to be static, and hostnames can also exhibit issues (which in my case were largely due to the number of computers in use). Anyway, my preference for future work would be to use MAC addresses in some way as they should be unique and static, even if the IP address or hostname is changed. I have java code to retrieve them (cross platform), and also a Mac OS X native external if either is of interest.

if your network traffic is not massively high then you could consider multicasting all data with a MAC address prefix for the relevant computer (or using a tag that you have assigned to that MAC address), and then filtering at the client end.

If you really need to send data just to one computer then obviously you’ll need to retrieve IP addresses and do it that way.



Oct 26 2010 | 9:11 pm

I once used a combination of maxhole and the normal udp objects to connect two computers with unknown ip addresses:

on loadbang, each computer sends its own ip address to maxhole. This is received by all computers (on the same subnet), who, if they haven’t sent their address already, respond by sending their ip address or if they have, make a connection using udpsend and udpreceive.

Another, much slower option would be to just ping a whole range of ip-addresses using a shell object and see if you get any response.

Oct 26 2010 | 9:55 pm

Hi guys,

Thanks for the fast replies – much appreciated.

Using a multicast message should work absolutely fine – I was thinking of much more complicated solutions (directly querying the DHCP table etc.) so thanks for setting me straight. I have however come up against another problem! See below…..

Alex – I’ve decided to use the DHCP server to permanently associate IP addresses to particular MAC addresses when new people connect to the network. I do indeed need to make sure that people have consistent IP’s when they connect in case they lose their connection mid-performance and there’s no time to change other settings. Since I’m doing this for a ‘laptop orchestra’ I’ll have a small but limited turnover in personnel from rehearsal to rehearsal and a some time for admin at the beginning of each, so it shouldn’t be too much trouble to organise. I think that my levels of network traffic will be too large to multicast everything. If there’s a reason why this wouldn’t work I’d appreciate a heads up though!

My only problem now lies in getting [mxj net.local] to do what I want. I’ve been wrestling with it for the last couple of hours and can’t seem to get it under control.

When I send it a bang it outputs a long list (around 20) different network interfaces from which to choose (of the types net, eth or ppp) which I’m then having to manually cycle through to discover which is the one currently being used in order to get the local IP. Is there a way to automatically identify which interface is being used for the current connection? Unless I can do this I can’t see a way to automatically respond correctly to a broadcast request. The interface ‘en1’ used in the help file doesn’t return anything on my machine.

Again, networking is really not my strong-point so apologies for anything stupid!

Thanks again,


Oct 26 2010 | 10:10 pm


Apologies – it took me so long to write my last post that you replied in the meantime!

I thought about pinging an IP range with a script and using that data, but ideally I want to do it automatically from within a Max patch running cross-platform and it seemed too complicated to deal with different OS’s – perhaps it’s easier than I think though?

The maxhole idea is a good one, but again depends on reliably identifying local IP’s – how did you manage that?



Oct 27 2010 | 7:45 am

If you know the ip range in which the dhcp server hands out addresses (can be found in the router settings), you can iterate through the interfaces that net.local spits out and check if an address belongs to this range. Then you can assume that that must be the network interface you need.

Common ranges for home network setups: to ( is the router) to ( is the router) to ( is the router)

Oct 28 2010 | 11:20 am


That’s great – obvious really! thanks!


Oct 28 2010 | 3:35 pm

In case anyone else needs to do this, below is my solution. It returns any IP in the range Just change the numbers in the [if ] object to change the range.

I’m sure it’s possible to do it more efficiently (combine the two [regexp]’s for example), but it seems to work!


-- Pasted Max Patch, click to expand. --

Nov 30 2010 | 10:49 pm

This is maybe a stupid question (didn’t get all of what you guys were talking about :) But are you able to get the IP address of a device UDP transmitting on a specific port (or is this, what you guys are trying to figure out?). I want to automaticly hook up two iphones with touchOSC to my laptop, and getting the data into max. So far alle the UDP send/recieving is working perfectly. The only annoying thing is, as you mentioned earlie in this post, that you have to type in the ip addresses for each cell phone. Any ideas? (or is it the same approach as discussed in this debate?

Feb 27 2011 | 8:32 am

Hi lmnk

I have the same kind of question. I’m trying to get MAX to understand which mobile phones are connected to the wifi, so that people can hook up while a concert is running. The idea is to have people record bits of the performance, remote controlling the max patch, and then afterwards they can improvise on ‘their favorite bits’ using their tablet phone using touchOSC.

In short: how can I have MAX automatically detect the devices that are hooking up to the wifi (the same one as the hosting MacBook Pro is on)?

Viewing 12 posts - 1 through 12 (of 12 total)

Forums > MaxMSP