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
Hello Roman,
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, 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@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
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@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/l istinfo/pd-list
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/lis tinfo/pd-list
Hi Roman,
I'm not sure but may be these two croos-platform apps will help sending and analyzing received packets:
Salutti, Lucarda.
Mensaje telepatico asistido por maquinas.
On 12/16/2017 9:41 PM, Roman Haefeli wrote:
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@lists.iem.atmailto:Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/l istinfo/pd-list
Pd-list@lists.iem.atmailto:Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/lis tinfo/pd-list
Pd-list@lists.iem.atmailto:Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
Le 17/12/2017 à 01:41, Roman Haefeli a écrit :
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).
It is. If you run : $ route -n
you can see which interface is connected to the gateway (router). From Pd, i can't see a solution.
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.
Or not. Your router can be connected to 3 or more different networks : 1 public for internet 2 local
But it is not a problem to send a packet from a local network to the other local network, the router should do the job (depending of its configuration).
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.
Yes, [tcpclient] only need the IP and the listening port of the server. And i can't see an object from Pd library doing this job.
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?
Maybe an other object (but not [tcpclient] ?) could return the local IP. Sending this local IP to the public server could help to create a direct connection between clients on local networks... I am also interested to know if there is a better solution. ++
Jack
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@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/l istinfo/pd-list
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/lis tinfo/pd-list
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
Hi Roman,
If the server is brokering the traffic then you never need to know the private network addresses as NAT will map them to public port numbers and the router will map the returned packets back to local addresses.
But I guess you want to use the server to do peer discovery and then having the two clients communicate directly.
Aren't there some more genral network utility objects in Pd?
In my wishes we would have: [tcpdump] and [hping], one to dump traffic, maybe in hex to avoid Pd's fussiness about control characters, and one to craft any and all packets according to a template sent in a prior message.
And to get really serious about Pd as a network utility how about [sock], an object to be set up as a raw socket?
cheers Andy
On Sun, Dec 17, 2017 at 01:41:38AM +0100, Roman Haefeli wrote:
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.
On Son, 2017-12-17 at 10:48 +0000, Andy Farnell wrote:
If the server is brokering the traffic then you never need to know the private network addresses as NAT will map them to public port numbers and the router will map the returned packets back to local addresses.
But I guess you want to use the server to do peer discovery and then having the two clients communicate directly.
Exactly, that's the idea.
Aren't there some more genral network utility objects in Pd?
Yes, iemnet comes with [tcpclient] and [udpclient], which accept and output bytes. They're pretty raw and probably close to your idea of a [sock] object. However, they don't output all properties of the current socket.
What I wish to be able to do is done in python like this:
#!/usr/bin/python import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 53)) print(s.getsockname()[0]) s.close()
In my wishes we would have: [tcpdump] and [hping], one to dump traffic, maybe in hex
All networking objects, including the ones from vanilla, are able to deal with bytes represented as numbers. I think that's far more versatile in Pd to use than hex.
to avoid Pd's fussiness about control characters, and one to craft any and all packets according to a template sent in a prior message.
And to get really serious about Pd as a network utility how about [sock], an object to be set up as a raw socket?
I think we're pretty well served with what we have already. What use cases do you have in mind that aren't covered yet?
Roman
In Unix, all is a file, did you try to look inside the /proc/net directory to find your local IP ? Then, [text] can be used to load a specific file. ++
Jack
Le 17/12/2017 à 14:59, Roman Haefeli a écrit :
On Son, 2017-12-17 at 10:48 +0000, Andy Farnell wrote:
If the server is brokering the traffic then you never need to know the private network addresses as NAT will map them to public port numbers and the router will map the returned packets back to local addresses.
But I guess you want to use the server to do peer discovery and then having the two clients communicate directly.
Exactly, that's the idea.
Aren't there some more genral network utility objects in Pd?
Yes, iemnet comes with [tcpclient] and [udpclient], which accept and output bytes. They're pretty raw and probably close to your idea of a [sock] object. However, they don't output all properties of the current socket.
What I wish to be able to do is done in python like this:
#!/usr/bin/python import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 53)) print(s.getsockname()[0]) s.close()
In my wishes we would have: [tcpdump] and [hping], one to dump traffic, maybe in hex
All networking objects, including the ones from vanilla, are able to deal with bytes represented as numbers. I think that's far more versatile in Pd to use than hex.
to avoid Pd's fussiness about control characters, and one to craft any and all packets according to a template sent in a prior message.
And to get really serious about Pd as a network utility how about [sock], an object to be set up as a raw socket?
I think we're pretty well served with what we have already. What use cases do you have in mind that aren't covered yet?
Roman
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
On Son, 2017-12-17 at 01:41 +0100, Roman Haefeli wrote:
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?
Here it is: https://git.iem.at/pd/iemnet/issues/1