[PD] IP address of local machine

Roman Haefeli reduzent at gmail.com
Sun Dec 17 01:41:38 CET 2017


On Sam, 2017-12-16 at 21:26 +0100, Jack wrote:
> Your router has a public and local IP. So, i guess your local machine
> has only a local IP. Then, your local machine need to pass through
> your
> router to access remote server. Your router has NAT rules to know
> which
> local machine to route the content from the remote server.
> I don't really understand what exactly you are looking for

Sorry for not being more clear. I try to rephrase. I like to know what
local IP address a [tcpclient] or [udpclient] connection is using. So,
if my wifi interface is configured to 192.168.1.50 and this interface
is used for communicating to the outside world, how can I get that IP
from within Pd? Your suggestions may work by using [shell], but still
they show all kinds of interfaces and IP addresses and its not trivial
to determine the one that is used to talk to the default gateway (or by
specific connection). 

I would like to implement a technique called UDP hole punching[1] in
Pd. Before two clients talk to each other directly, they exchange some
information by talking to a server with a public IP address that acts
as a man-in-the-middle. As a result, the clients know the public IP
address and the bind port of their peer. This works well so far, even
in my patch. However, if both clients are in the same local network,
they can't establish a connection because they try to connect to the
public IP address of their own router. So, in order to overcome this
limitation, my idea was to check if my router's public IP address is
the same as the one of my peer. If they are, it means both clients are
part of the same local network. In that case, they would use the public
server to exchange each other's local IP addresses. However,
[tcpclient] seems to have no notion of the local IP address of an
established connection. So the patch actually doesn't know what IP
address it is using and thus cannot tell its peer.

Using [shell] and a script based on 'ip addr show' seems tedious and
not very reliable, considering the information needed is part of every
packet sent and received by [tcpclient]. 

If there's no easy way, I might turn that into a feature request for
iemnet's [udpclient] and [tcpclient] to print the src IP address and
src port on the status outlet. Does that make sense?


Roman


[1] https://en.wikipedia.org/wiki/UDP_hole_punching


> , but here
> some possible answer (on linux) :
> 
> to get your ip address (local)
> $ ip addr
> to get the IP address (local) of the router :
> $ ip route
> to get the public address of the router :
> $ curl -s http://whatismyip.akamai.com/
> or
> $ netcat -w 5 4.ifcfg.me 23
> or
> $ nc -w 5 4.ifcfg.me 23
> 
> There is also other command lines (ifconfig (instead of ip addr),
> route
> -n (instead ip route), etc.).
> ++
> 
> Jack
> 
> 
> 
> Le 16/12/2017 à 17:35, Roman Haefeli a écrit :
> > 
> > Hey all
> > 
> > Is there a simple cross-platform way for a patch to know the main
> > IP
> > address of the local machine? Assume the patch is connected to a
> > remote
> > server and is able to request its public IP address. What I like to
> > find out is if the local patch is communicating through NAT or
> > directly
> > to the remote server. 
> > 
> > An incoming IP packet from the remote server would contain that
> > information in the destination IP address field of the IP header,
> > but
> > the network objects I'm using ([tcpclient] and [udpclient]) don't
> > expose that information. 
> > 
> > Maybe there are other ways?
> > 
> > Roman
> > 
> > 
> > 
> > _______________________________________________
> > Pd-list at lists.iem.at mailing list
> > UNSUBSCRIBE and account-management -> https://lists.puredata.info/l
> > istinfo/pd-list
> > 
> 
> _______________________________________________
> Pd-list at lists.iem.at mailing list
> UNSUBSCRIBE and account-management -> https://lists.puredata.info/lis
> tinfo/pd-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20171217/d55b96bc/attachment.sig>


More information about the Pd-list mailing list