Getting IP Address of localhost
(*** This is not a question, but rather a feature request.)
Using [mxj net.ip], one can get the IP address of the localhost, that is 127.0.0.1,
but this is apparently NOT the IP address of the current machine.
If [mxj net.ip] supports such feature, it would be very useful.
For my own project, I created a very simple Java external to get the IP address of the current machine with this simple code:
Use "mxj net.local" instead.
[mxj net.local] builds up the list of the available network interfaces,
and selecting one of them returns an IP address, but none of them is correct.
Can you confirm that it works as expected on your machine?
(Maybe a problem in Mac OS X 10.8 Mountain Lion.)
I haven’t tested all interfaces in net.local but when looking at this again I think you’re approaching this in the wrong way.
When looking at net.ip (which you used first) you make some false assumptions it seems. You fed it ‘localhost’ (which is basically a computer name) which the net.ip routine then resolved into 127.0.0.1. You say its not the IP address of the current computer, but that is incorrect. When networked computers have a minimum of 2 IP addresses assigned to them; one for the localhost interface and one for the regular network interface.
However… It seems you’re overlooking something here. All net.ip does is resolve hostnames. Feed it a hostname and it looks up the associated IP address. So if you want to know the (public) IP address of your computer just feed it the (public) hostname. I named my (Windows) machine ‘plwin7′, and when I feed that into net.ip I get my lan IP address.
I think that could be much easier on you.
On my Mac, I put the name of the machine, and it returns the right IP address.
I did not realise this would work.
But still this is not really perfect,
because my patch then should get the name of the current machine.
(Do you have any clue?)
To be clear:
This is about the IP address in a local network.
For example, my Mac is attached to a router and the IP address is 22.214.171.124.
And what I want to do is getting this IP address automatically in Max.
But both [mxj net.ip] and [mxj net.local] have no way to get this IP address (unless the name of the machine is given).
no problem here, did you try to connect a print object to the left output of mxj net.local? the helppatch design with its umenu-display is suboptimal, did you do the things in right order:
2. select umenu active networking connection (probably "en1")
3. check umenu "ip-adresses" (click on arrows, what you want might be hidden)
Oops, you are right, tobiasros.
The IP address I want to get is hidden there.
One thing I’m still concerned is that I need to choose the right network interface.
It shows four interfaces on my Mac, and the one I need is "en0", but this will be surely different on other machines.
The easiest solution for me is to use my own Java external with this simple code (as in my first posting):
> InetAddress.getLocalHost().getHostAddress() <
But now I begin to wonder if this approach may not be reliable in certain occasions, for example there may be more than one network connections at the same time (ethernet and wi-fi), and I need to choose one of them somehow.
Anyway, thanks a lot for your help, ShelLuser and tobiasros!!!
Well, not knowing what network device to use is basically a standard issue with tcp/ip based networking. And its solved through the so called ‘routing table’. This routing table is something you normally have no control over, but it tells the computer how it should reach the outside world. And to make sure you don’t have to specify every goal on the planet there’s also something as the ‘default route’. This basically tells your computer "if you can’t reach the goal directly, use this interface (or route, or…).
So; I don’t know what your exact goal is here but I do wonder if it isn’t possible to skip the whole identification step and just go along to send out whatever you’re after? Basically let the computer sort it all out.
dont forget that your computer could be part of more than one network. there is not only local adresses and your IP for the intenet, therhe could also be a second ethernetcard for another network. this is why it is so surprisingly not straight forward to find the internet IP adress or the current/default interface using java.
one way how to find your own IP easily is when the application is a service and there is a client connected via in the internet. asking the connected client is an often used way for a server application ti find/know/show its one adress.
Using [mxj net.local] it is still not at all clear to me what all of the abbreviations that populate the umenu mean. I’m looking for a unique moniker to use as an (at least relatively) unchanging identifier of the computer my patch is running on. If there was a way to get the actual name of the computer that would be ideal, but I thought I might be able to use the public IP address instead. However the only abbreviation that returns an actual IP address, besides lo, is net6, and it is not my public IP (according to sites like mypublicip.com). A lot of the abbreviations return gibberish like
What does that stuff mean? How can I actually get my public IP address automatically using Max?
what you get seems to be a corrupted version (wrongly parsed) of your IP address in the format IPv6. If you want to get the public IP address this will do (plain max :) ):
----------begin_max5_patcher---------- 667.3ocyWssiaBCD8YxWgkelh.CDH8Gnpu02qphLvnrdEXiLlrIZ09uWeARS 1sgEkaZeAEOdr8bNywy375BObgXGzgQeG8ajm2qK77rlLF7FF6gan6JqocV2 vkhlFfqv9t4TvNk09O.EpsunlUh94u1lLNeMiCkhdt0IxfwVpp7IFeyZITpb GdTdVPnOJOLH0GsZk42wZKn+Lrjh9hhZniUAF+iGrxprmsn34uQBwm3pYhnA Kcp8NC3Qe38MLdMn5N1MsQQuZzZnw3aKVX93OSxonWoD7wCwsYp8sfCi3BJe C9.j9OrPbBwf+3HKYPRF+dXMGA3nb70.unK.db3E8I+gTuBUiJNKnw9yA3gg FrFszB4ThE3jy.7kWEvIW.vaftN5F3CHeiVzyZ2lTHTAu7DUw5Z1yZoUUR8B BzWUNOqLC1HO2RCgQSxFjYxFj6sLPp2V.UHp1OoVXZjGYK.PxsDvxrIQd3Ug 7aoNfDDEuJfDRBHowWVNOJI1c02lzixWNEzW8vy4ScCX5T9jo63XmD2VvOcx zc1WEcdEqTcV3ZljI3T4dqV2eNZd2scRhE9otK.mgDRuJRHYbwzsP0Z89oig 0TkRxzMtbOCv6.W3gglBvdzg9CVZoRZCn.4ZfSGZxZ6S5n1aDAq8oWVOWJdN sUbxrjI0WjaVWE6tae4y6dYkMBM1OkS5D8xxQzMVYC8ufrB5TLN0.5icJ+Dm dhUUA7ixVZdpyjipN+iYlc7n63hh9j3I6gENj4vNKerrymEOoOtvYNzC4gEN oyP57N89ckclyUqUmDy2yvI6NJcbkgnssaAY2vVZCDcA1mERyvLe6PF2Mzti XIrkM5u8OZgoRcgUktpZuzUXbWt6M33FQEH48rgVr5S9sE+EOyrPhC -----------end_max5_patcher-----------
As a unique identifier it has limitations as all machines within the same network, using the same internet gateway (router) will have the same IP.
More reliable would be to query your MAC address of the ethernet or wifi card. At least in theory the MAC address should be unique for each interface. But afaik there is no Java class for that that ships with Max. You wound need to write your own. Here’s a starting point:
Here’s a quick and dirty java class that reports the MAC address of your network interface. It’s jusr a 5 min speed coding, but works here on OS X. Just send bang into the the first inlet and the left outlet will report the MAC address.
Best place in Max7 is to put the .class and .java files in a java folder of a custom package – then restart Max.
Forums > Java