Sniffing IP addresses
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!
you can use the udpsend object to broadcast a message like "hello i am 192.168.0.1, 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…
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.
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.
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.
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!
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?
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:
192.168.1.2 to 192.168.1.255 (192.168.1.1 is the router)
192.168.2.2 to 192.168.2.255 (192.168.2.1 is the router)
10.0.0.151 to 10.0.0.255 (10.0.0.150 is the router)
That’s great – obvious really! thanks!
In case anyone else needs to do this, below is my solution. It returns any IP in the range 192.168.1.xxx. 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. --Copy all of the following text. Then, in Max, select New From Clipboard.----------begin_max5_patcher---------- 784.3ocyXstaaBCE92oR8cvBMU0nkg7Ev.UJZZOGqUSjfap6HFTvQKaQ8ce9 xf0b2dizzDEYNGaLe9ye9bNj0We0ffIUqXMAf6.eELXvZkmAFeZOCZcLHXd9 pok4MlAFHX+nZxyAi9SeR1Jowe8BtPB30c87XkPJxmyL89kE77xtt3EFmp44 SIjMtgF9uL2.BGBa8KVNmKJYRyyG8JuUKkst6Fbctb5SbwrusfMUZWYHXlZx .XhdNAQIFCXHD7f4dd45qzsplQ+2jPCqDf7jAno9w.38y.cts9j+rlYW9ASx EyBFABB.ObDVJyvNnTptgPOijD+QvsefiFOFkgGBt4FsEFLdL.QSasIF6g.4 SLA.AXkML.zShMl5GwR1OwhNHw5DgRIFBEg5AFcNqoIeFaWJUwjgJ1KDFR7k jf8h56ekjZOaZomDpUCdVjcKE04S+N.Z+5IMEA6kvTQGjlTAO0mQ2swEMl83 ZZ1Y7P6B1L1pZvs2946tW8oXM596GQdQec3v01KZcNzSxEQ6ExM9vZvQa86n jpkLisRw3yImp.JCjWWyDEdRYDbuPY3iSYmllhsjE5MP4YTXebnQwcZCO4SL 9ckDLJ0n9rQEQYQuOEgH3EWDlZplKNo2TgSVJkUh8lBHvmEE53kic5SVc64m sc94qdFHXxvxpouZ+0wx1eeD9wVRexgKo2NEAkbwNumiYN0crE20TsbwzVbz VftpjgNvTvZjbQtjqzI+cT5Bod8ndhWTvDa7tIy4E0Upb5Ms09fBi03NwdXO sy5Xa1NCacVUUoyt.ajOv1dXCAMYFih1wnc8jD2uqmsI38udzuOoeaC8B3z0 GBvmjroaNJGzHpLAHJklfULZro.ORFQSrFq9C6HmvtWBEDNJLkn9P6vNV812 8O1gNg82dQw1O18CtsCu7FAN2BOnqK5B.Nyi8jfKBdQ.GA6x1J5xn4RbAajK ytJxsH39hsLpNlhs5OcVG3VFXa9Ha5n9JaThKBTj2BzDSr8XShzTy+bzFWaV V10q959ID5YYSYOUhc8UpleC0up4WB -----------end_max5_patcher-----------
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?
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)?
Forums > MaxMSP